geheim

package module
v1.29.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 21 Imported by: 1

README

geheim

Go Reference

the cipher utility

Documentation

Index

Constants

View Source
const (
	DefaultCipher = AES_256
	DefaultMode   = CTR
	DefaultKDF    = Argon2id
	DefaultMAC    = HMAC
	DefaultMD     = SHA_256
	DefaultSec    = 10
)
View Source
const (
	MinSec = 0
	MaxSec = 20
)
View Source
const (
	CipherDesc = "cipher"
	ModeDesc   = "stream mode"
	KDFDesc    = "key derivation"
	MACDesc    = "message authentication"
	MDDesc     = "message digest"
	SecDesc    = "security level"
)
View Source
const Magic = 1195920895
View Source
const Version = v7

Variables

View Source
var (
	ErrKey    = errors.New("geheim: empty key")
	ErrHeader = errors.New("geheim: malformed header")
	ErrSign   = errors.New("geheim: signature verification failed")

	ErrCipher = fmt.Errorf("geheim: invalid %s (%s)", CipherDesc, CipherString)
	ErrMode   = fmt.Errorf("geheim: invalid %s (%s)", ModeDesc, ModeString)
	ErrKDF    = fmt.Errorf("geheim: invalid %s (%s)", KDFDesc, KDFString)
	ErrMAC    = fmt.Errorf("geheim: invalid %s (%s)", MACDesc, MACString)
	ErrMD     = fmt.Errorf("geheim: invalid %s (%s)", MDDesc, MDString)
	ErrSec    = fmt.Errorf("geheim: invalid %s (%d~%d)", SecDesc, MinSec, MaxSec)
)
View Source
var (
	MetaSize   = int64(binary.Size(meta))
	HeaderSize = int64(binary.Size(header))
	Overhead   = MetaSize + HeaderSize
)
View Source
var CipherNames = map[Cipher]string{
	AES_256:  "AES-256",
	ChaCha20: "ChaCha20",
}
View Source
var CipherString = getOptionString(ciphers[:], CipherNames)
View Source
var KDFNames = map[KDF]string{
	HKDF:     "HKDF",
	Argon2id: "Argon2id",
	Scrypt:   "Scrypt",
}
View Source
var KDFString = getOptionString(kdfs[:], KDFNames)
View Source
var MACNames = map[MAC]string{
	HMAC: "HMAC",
}
View Source
var MACString = getOptionString(macs[:], MACNames)
View Source
var MDNames = map[MD]string{
	SHA3_224:    "SHA3-224",
	SHA3_256:    "SHA3-256",
	SHA3_384:    "SHA3-384",
	SHA3_512:    "SHA3-512",
	SHA_224:     "SHA-224",
	SHA_256:     "SHA-256",
	SHA_384:     "SHA-384",
	SHA_512:     "SHA-512",
	SHA_512_224: "SHA-512/224",
	SHA_512_256: "SHA-512/256",
	BLAKE2b_256: "BLAKE2b-256",
	BLAKE2b_384: "BLAKE2b-384",
	BLAKE2b_512: "BLAKE2b-512",
}
View Source
var MDString = getOptionString(mds[:], MDNames)
View Source
var ModeNames = map[Mode]string{
	CTR: "CTR",
	CFB: "CFB",
	OFB: "OFB",
}
View Source
var ModeString = getOptionString(modes[:], ModeNames)

Functions

func Decrypt

func Decrypt(r io.Reader, w io.Writer, key []byte, printFunc PrintFunc) (sign []byte, err error)

func DecryptArchive added in v1.25.3

func DecryptArchive(r io.Reader, w io.Writer, key []byte, printFunc PrintFunc) (sign, signex []byte, err error)

func DecryptVerify added in v1.3.1

func DecryptVerify(r io.Reader, w io.Writer, key, signex []byte, printFunc PrintFunc) (sign []byte, err error)

func Encrypt

func Encrypt(r io.Reader, w io.Writer, key []byte, cipher Cipher, mode Mode, kdf KDF, mac MAC, md MD, sec int, printFunc PrintFunc) (sign []byte, err error)

func EncryptArchive added in v1.25.3

func EncryptArchive(r io.Reader, w io.Writer, key []byte, size int64, cipher Cipher, mode Mode, kdf KDF, mac MAC, md MD, sec int, printFunc PrintFunc) (sign []byte, err error)

func FormatSize added in v1.6.10

func FormatSize(n int64) string

func GetMemory added in v1.24.1

func GetMemory(sec int) int64

func Verify added in v1.25.1

func Verify(x, y []byte) error

Types

type Cipher added in v1.4.0

type Cipher int
const (
	AES_256 Cipher = 1 + iota
	ChaCha20
)
type Header interface {
	Read(io.Reader) error
	Write(io.Writer) error
	Get() (cipher Cipher, mode Mode, kdf KDF, mac MAC, md MD, sec int, salt, nonce []byte)
	Set(cipher Cipher, mode Mode, kdf KDF, mac MAC, md MD, sec int, salt, nonce []byte)
}

type KDF added in v1.4.0

type KDF int
const (
	HKDF KDF = 1 + iota
	Argon2id
	Scrypt
)

type MAC added in v1.4.0

type MAC int
const (
	HMAC MAC = 1 + iota
)

type MD added in v1.4.0

type MD int
const (
	SHA3_224 MD = 1 + iota
	SHA3_256
	SHA3_384
	SHA3_512
	SHA_224
	SHA_256
	SHA_384
	SHA_512
	SHA_512_224
	SHA_512_256
	BLAKE2b_256
	BLAKE2b_384
	BLAKE2b_512
)

type MDFunc added in v1.22.4

type MDFunc func() hash.Hash

type Meta added in v1.6.4

type Meta struct {
	Magic   uint32
	Version uint32
}

func NewMeta added in v1.6.4

func NewMeta() *Meta

func (*Meta) Header added in v1.6.4

func (m *Meta) Header() (Header, error)

func (*Meta) Read added in v1.6.4

func (m *Meta) Read(r io.Reader) error

func (*Meta) Write added in v1.6.4

func (m *Meta) Write(w io.Writer) error

type Mode

type Mode int
const (
	CTR Mode = 1 + iota
	CFB
	OFB
)

type PrintFunc

type PrintFunc func(version int, header Header, keys, keyCipher, keyMAC []byte) error

func NewDefaultPrintFunc added in v1.22.5

func NewDefaultPrintFunc(w io.Writer) PrintFunc

type ProgressWriter added in v1.19.1

type ProgressWriter struct {
	TotalBytes int64
	// contains filtered or unexported fields
}

func NewProgressWriter added in v1.23.2

func NewProgressWriter(total int64) *ProgressWriter

func (*ProgressWriter) Progress added in v1.19.1

func (w *ProgressWriter) Progress(duration time.Duration, done <-chan struct{})

func (*ProgressWriter) Reset added in v1.23.2

func (w *ProgressWriter) Reset()

func (*ProgressWriter) Write added in v1.19.1

func (w *ProgressWriter) Write(p []byte) (n int, err error)

type StreamMode added in v1.22.0

type StreamMode func(cipher.Block, []byte) cipher.Stream

Directories

Path Synopsis
cmd
ghm
xp

Jump to

Keyboard shortcuts

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