crypto

package
v0.0.0-...-9948cb5 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChecksumSize = 512 / 8
	ChunkSize    = 256
	SaltSize     = 512
	IVSize       = aes.BlockSize
	DataSize     = ChunkSize - 1
	KeySize      = 32
	HMACKeySize  = 256
)
View Source
const DefaultSaltSize = 1024

Variables

View Source
var (
	ErrDecryptionFailed = errors.New("decryption failed")
)

Functions

This section is empty.

Types

type Argon

type Argon struct {
	Time    uint32 `json:"time"`
	Memory  uint32 `json:"memory"`
	Threads uint8  `json:"threads"`
}

func DefaultArgon

func DefaultArgon() (a Argon)

func (*Argon) Release

func (a *Argon) Release()

type Job

type Job struct {
	Key, Data []byte
	Argon     Argon
	SaltSize  int
}

func (*Job) Decrypt

func (j *Job) Decrypt(secret *Secret) (err error)

Decrypt populates the Data field of Job struct with the decrypted secret on success On failure returns ErrDecryptionFailed

func (*Job) Encrypt

func (j *Job) Encrypt() (secret *Secret)

Prepares a secret structure with a ready to use IV and salts

func (*Job) Release

func (j *Job) Release()

type Secret

type Secret struct {
	// Configuration for the argon function
	Argon Argon `json:"argon"`

	// Initialization Vector (IV)
	// To initialize it always all the Init() function
	IV []byte `json:"iv"`

	// Key salt is the Argon Salt to use for the key stretching process
	// To initialize it always all the Init() function
	KeySalt []byte `json:"keySalt"`

	// Salt used for the HMAC calculation
	HMACSalt []byte `json:"hmacSalt"`

	// The actual cipher text created after encrypting the msg
	// Divided in blocks of 256 bytes
	// The last block correspond to the actual data and a padding. Of which to prevent Padding oracle attack
	// The padding is always a valid number
	Cipher []byte `json:"cipher"`

	// HMAC is used to verify the authenticity of the encrypted cipher
	// This will ensure the algorithm enver tries to decrypt data user never encrypted
	HMAC []byte `json:"hmac"`
}

func (*Secret) Release

func (s *Secret) Release()

Jump to

Keyboard shortcuts

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