stream

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const BUFFER_SIZE int = 16 * 1024
View Source
const IV_SIZE int = 16
View Source
const V1 byte = 0x1

Variables

View Source
var ErrInvalidHMAC = errors.New("Invalid HMAC")

ErrInvalidHMAC for authentication failure

View Source
var (
	ScryptParams = scrypt.Params{N: 65536, R: 1, P: 2, SaltLen: 16, DKLen: 32}
)

Functions

func DecFromTemp added in v0.0.4

func DecFromTemp(tmpFile string, pass []byte, saveto string, salt string)

DecFromTemp decrypt from temp file

func Decrypt added in v0.0.4

func Decrypt(in io.Reader, out io.Writer, keyAes, keyHmac []byte) (err error)

Decrypt the stream and verify HMAC using the given AES-CTR and SHA512-HMAC key Do not trust the out io.Writer contents until the funtion returns the result of validating the ending HMAC hash.

func EncToTemp added in v0.0.4

func EncToTemp(filepath string, pass []byte) string

EncToTemp encrypt file to a temp file

func Encrypt added in v0.0.4

func Encrypt(in io.Reader, out io.Writer, keyAes, keyHmac []byte) (err error)

Encrypt the stream using the given AES-CTR and SHA512-HMAC key

func GenSalt added in v0.0.4

func GenSalt() []byte

Types

type StreamDecrypter

type StreamDecrypter struct {
	Source io.Reader
	Block  cipher.Block
	Stream cipher.Stream
	Mac    hash.Hash
	Meta   StreamMeta
}

StreamDecrypter is a decrypter for a stream of data with authentication

func NewStreamDecrypter

func NewStreamDecrypter(key []byte, meta StreamMeta, cipherText io.Reader) (*StreamDecrypter, error)

NewStreamDecrypter creates a new stream decrypter

func (*StreamDecrypter) Authenticate

func (s *StreamDecrypter) Authenticate() error

Authenticate verifys that the hash of the stream is correct. This should only be called after processing is finished

func (*StreamDecrypter) Read

func (s *StreamDecrypter) Read(p []byte) (int, error)

Read reads bytes from the underlying reader and then decrypts them

type StreamEncrypter

type StreamEncrypter struct {
	Source io.Reader
	Block  cipher.Block
	Stream cipher.Stream
	Mac    hash.Hash
	IV     []byte
}

StreamEncrypter is an encrypter for a stream of data with authentication

func NewStreamEncrypter

func NewStreamEncrypter(key []byte, plainText io.Reader) (*StreamEncrypter, error)

NewStreamEncrypter creates a new stream encrypter

func (*StreamEncrypter) Meta

func (s *StreamEncrypter) Meta() StreamMeta

Meta returns the encrypted stream metadata for use in decrypting. This should only be called after the stream is finished

func (*StreamEncrypter) Read

func (s *StreamEncrypter) Read(p []byte) (int, error)

Read encrypts the bytes of the inner reader and places them into p

type StreamMeta

type StreamMeta struct {
	// IV is the initial value for the crypto function
	IV []byte
	// Hash is the sha256 hmac of the stream
	Hash []byte
}

StreamMeta is metadata about an encrypted stream

Jump to

Keyboard shortcuts

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