crypto

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2021 License: GPL-3.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptReader

func DecryptReader(b cipher.Block, iv []byte, r io.Reader) (data.Reader, error)

DecryptReader creates a data.Reader type from the specified block Cipher, IV and Reader. This is used to Decrypt data. This function returns an error if the blocksize of the Block does not equal the length of the supplied IV.

func DecryptWriter

func DecryptWriter(b cipher.Block, iv []byte, w io.Writer) (data.Writer, error)

DecryptWriter creates a data.Writer type from the specified block Cipher, IV and Writer. This is used to Decrypt data. This function returns an error if the blocksize of the Block does not equal the length of the supplied IV.

func EncryptReader

func EncryptReader(b cipher.Block, iv []byte, r io.Reader) (data.Reader, error)

EncryptReader creates a data.Reader type from the specified block Cipher, IV and Reader. This is used to Encrypt data. This function returns an error if the blocksize of the Block does not equal the length of the supplied IV.

func EncryptWriter

func EncryptWriter(b cipher.Block, iv []byte, w io.Writer) (data.Writer, error)

EncryptWriter creates a data.Reader type from the specified block Cipher, IV and Writer. This is used to Encrypt data. This function returns an error if the blocksize of the Block does not equal the length of the supplied IV.

func NewAes

func NewAes(k []byte) (cipher.Block, error)

NewAes attempts to create a new AES block Cipher from the provided key data. Errors will be returned if the key length is invalid.

func NewReader

func NewReader(c Reader, r io.Reader) data.Reader

NewReader creates a data.Reader type from the specified Cipher and Reader.

func NewSource

func NewSource(seed interface{}) rand.Source

NewSource creates a random Source from the provided interface. This function supports all types of Golang primitives.

func NewSourceEx

func NewSourceEx(rounds int, seed interface{}) rand.Source

NewSourceEx creates a random Source from the provided interface. This function supports all types of Golang primitives. This function allows for supplying the rounds value, which defaults to the value of 4.

func NewWriter

func NewWriter(c Writer, w io.Writer) data.Writer

NewWriter creates a data.Writer type from the specified Cipher and Writer.

func SHA512

func SHA512(b []byte) []byte

SHA512 returns the SHA512 value of the provided byte array. This function is not recommended for big arrays.

Types

type CBK

type CBK struct {
	// Random Source to use for data generation from keys.
	// This source MUST be repeatable.
	Source rand.Source

	A, B byte
	C, D byte
	// contains filtered or unexported fields
}

CBK is the representation of the CBK Cipher. CBK is a block based cipher that allows for a variable size index in encoding.

func NewCBK

func NewCBK(d int) *CBK

NewCBK returns a new CBK Cipher with the D value specified. The other A, B and C values are randomally generated at runtime.

func NewCBKEx

func NewCBKEx(d int, size int, source rand.Source) (*CBK, error)

NewCBKEx returns a new CBK Cipher with the D value, BlockSize and Entropy source specified. The other A, B and C values are randomally generated at runtime.

func (CBK) BlockSize

func (e CBK) BlockSize() int

BlockSize returns the cipher's block BlockSize.

func (*CBK) Decrypt

func (e *CBK) Decrypt(dst, src []byte)

Decrypt decrypts the first block in src into dst. Dst and src must overlap entirely or not at all.

func (CBK) Deshuffle

func (e CBK) Deshuffle(b []byte)

Deshuffle will reverse the switch around the bytes in the array based on the Cipher bytes.

func (*CBK) Encrypt

func (e *CBK) Encrypt(dst, src []byte)

Encrypt encrypts the first block in src into dst. Dst and src must overlap entirely or not at all.

func (*CBK) Flush

func (e *CBK) Flush(w io.Writer) error

Flush pushes the remaining bytes stored into the buffer into the supplies Writer.

func (*CBK) Read

func (e *CBK) Read(r io.Reader, b []byte) (int, error)

Read reads the contents of the Reader to the byte array after decrypting with this Cipher.

func (*CBK) Reset

func (e *CBK) Reset() error

Reset resets the encryption keys and sets them to new random bytes.

func (CBK) Shuffle

func (e CBK) Shuffle(b []byte)

Shuffle will switch around the bytes in the array based on the Cipher bytes.

func (*CBK) Write

func (e *CBK) Write(w io.Writer, b []byte) (int, error)

Write writes the contents of the byte array to the Writer after encrypting with this Cipher.

type MultiSource

type MultiSource struct {
	// contains filtered or unexported fields
}

MultiSource is a struct that is a random Source that can use multiple source providers and spreads the calls among them in a random manner.

func NewMultiSource

func NewMultiSource(s ...rand.Source) *MultiSource

NewMultiSource creates a new MultiSource struct instance.

func (*MultiSource) Add

func (m *MultiSource) Add(s ...rand.Source)

Add will append the Source values to this MultiSource instance.

func (*MultiSource) Int63

func (m *MultiSource) Int63() int64

Int63 returns a int64 number between zero and the max value.

func (*MultiSource) Seed

func (m *MultiSource) Seed(n int64)

Seed will set the seed value of this MultiSource instance.

type Reader

type Reader interface {
	Read(io.Reader, []byte) (int, error)
}

Reader is an interface that supports reading bytes from a Reader through the specified Cipher.

type Writer

type Writer interface {
	Flush(io.Writer) error
	Write(io.Writer, []byte) (int, error)
}

Writer is an interface that supports writing bytes to a Writer through the specified Cipher.

type XOR

type XOR []byte

XOR is an alias for a byte array that acts as the XOR key data buffer.

func (XOR) BlockSize

func (x XOR) BlockSize() int

BlockSize returns the cipher's block size.

func (XOR) Decrypt

func (x XOR) Decrypt(dst, src []byte)

Decrypt preforms the XOR operation on the specified byte array using the cipher as the key.

func (XOR) Encrypt

func (x XOR) Encrypt(dst, src []byte)

Encrypt preforms the XOR operation on the specified byte array using the cipher as the key.

func (XOR) Flush

func (XOR) Flush(w io.Writer) error

Flush satisfies the crypto.Writer interface.

func (XOR) Operate

func (x XOR) Operate(b []byte)

Operate preforms the XOR operation on the specified byte array using the cipher as the key.

func (XOR) Read

func (x XOR) Read(r io.Reader, b []byte) (int, error)

Read satisfies the crypto.Reader interface.

func (XOR) Write

func (x XOR) Write(w io.Writer, b []byte) (int, error)

Write satisfies the crypto.Writer interface.

Jump to

Keyboard shortcuts

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