geheim

package module
v1.32.4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: MIT Imports: 20 Imported by: 1

README

geheim

Go Reference

the cipher utility

usage

$ ghm
usage: ghm [option]...
options:
  -P    progress
  -V    version
  -X    print signature hex
  -c int
        cipher (1:AES-256-CTR, 2:ChaCha20) (default 1)
  -d    decrypt
  -e int
        security (0:1MB, 1:2MB, 2:4MB, 3:8MB, 4:16MB, 5:32MB, 6:64MB, 7:128MB, 8:256MB, 9:512MB, 10:1GB, 11:2GB, 12:4GB, 13:8GB, 14:16GB, 15:32GB, 16:64GB, 17:128GB, 18:256GB, 19:512GB, 20:1TB) (default 10)
  -f    overwrite
  -h int
        hash (1:SHA3-224, 2:SHA3-256, 3:SHA3-384, 4:SHA3-512, 5:SHA-224, 6:SHA-256, 7:SHA-384, 8:SHA-512, 9:SHA-512/224, 10:SHA-512/256) (default 6)
  -i path
        input path (default "/dev/stdin")
  -k int
        key derivation (1:HKDF, 2:Argon2id, 3:Scrypt) (default 2)
  -o path
        output path (default "/dev/stdout")
  -p key
        key
  -s path
        signature path
  -v    verbose
  -x hex
        verify signature hex
  -z    archive
$ xp
usage: xp p                  # pair
       xp x <scalar> [point] # mult

Documentation

Index

Constants

View Source
const (
	DefaultCipher = AES_256_CTR
	DefaultKDF    = Argon2id
	DefaultHash   = SHA_256
	DefaultSec    = 10
)
View Source
const (
	MinSec = 0
	MaxSec = 20
)
View Source
const (
	CipherDesc = "cipher"
	KDFDesc    = "key derivation"
	HashDesc   = "hash"
	SecDesc    = "security"
)
View Source
const Magic = 1195920895
View Source
const Version = v8

Variables

View Source
var (
	MetaSize     = int64(binary.Size(meta))
	HeaderSize   = int64(binary.Size(header))
	OverheadSize = MetaSize + HeaderSize
)
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)
	ErrKDF    = fmt.Errorf("geheim: invalid %s (%s)", KDFDesc, KDFString)
	ErrHash   = fmt.Errorf("geheim: invalid %s (%s)", HashDesc, HashString)
	ErrSec    = fmt.Errorf("geheim: invalid %s (%s)", SecDesc, SecString)
)
View Source
var CipherNames = map[Cipher]string{
	AES_256_CTR: "AES-256-CTR",
	ChaCha20:    "ChaCha20",
}
View Source
var CipherString = getOptionString(ciphers[:], CipherNames)
View Source
var HashNames = map[Hash]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",
}
View Source
var HashString = getOptionString(hs[:], HashNames)
View Source
var KDFNames = map[KDF]string{
	HKDF:     "HKDF",
	Argon2id: "Argon2id",
	Scrypt:   "Scrypt",
}
View Source
var KDFString = getOptionString(kdfs[:], KDFNames)
View Source
var SecString = func() string {
	d := make([]string, MaxSec-MinSec+1)
	for i := MinSec; i <= MaxSec; i++ {
		d[i] = fmt.Sprintf("%d:%s", i, FormatSize(GetMemory(i), 0))
	}
	return strings.Join(d, ", ")
}()

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, hash Hash, kdf KDF, 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, hash Hash, kdf KDF, sec int, printFunc PrintFunc) (sign []byte, err error)

func FormatSize added in v1.6.10

func FormatSize(n int64, dec uint) 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_CTR Cipher = 1 + iota
	ChaCha20
)

type Hash added in v1.32.0

type Hash int
const (
	SHA3_224 Hash = 1 + iota
	SHA3_256
	SHA3_384
	SHA3_512
	SHA_224
	SHA_256
	SHA_384
	SHA_512
	SHA_512_224
	SHA_512_256
)
type Header interface {
	Read(io.Reader) error
	Write(io.Writer) error
	Get() (cipher Cipher, hash Hash, kdf KDF, sec int, salt, nonce []byte)
	Set(cipher Cipher, hash Hash, kdf KDF, sec int, salt, nonce []byte)
}

type KDF added in v1.4.0

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

type Meta added in v1.6.4

type Meta struct {
	Magic, 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 PrintFunc

type PrintFunc func(version int, header Header, key []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)

Directories

Path Synopsis
cmd
ghm
xp

Jump to

Keyboard shortcuts

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