cryptocore

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package cryptocore wraps OpenSSL and Go GCM crypto and provides a nonce generator.

Index

Constants

View Source
const (
	// KeyLen is the cipher key length in bytes. All backends use 32 bytes.
	KeyLen = 32
	// AuthTagLen is the length of a authentication tag in bytes.
	// All backends use 16 bytes.
	AuthTagLen = 16
)

Variables

View Source
var BackendAESSIV = AEADTypeEnum{"AES-SIV-512", "Go", siv_aead.NonceSize}

BackendAESSIV specifies an AESSIV backend. "AES-SIV-512-Go" in gocryptfs -speed.

View Source
var BackendGoGCM = AEADTypeEnum{"AES-GCM-256", "Go", 16}

BackendGoGCM specifies the Go based AES-256-GCM backend. "AES-GCM-256-Go" in gocryptfs -speed.

View Source
var BackendOpenSSL = AEADTypeEnum{"AES-GCM-256", "OpenSSL", 16}

BackendOpenSSL specifies the OpenSSL AES-256-GCM backend. "AES-GCM-256-OpenSSL" in gocryptfs -speed.

View Source
var BackendXChaCha20Poly1305 = AEADTypeEnum{"XChaCha20-Poly1305", "Go", chacha20poly1305.NonceSizeX}

BackendXChaCha20Poly1305 specifies XChaCha20-Poly1305-Go. "XChaCha20-Poly1305-Go" in gocryptfs -speed.

View Source
var BackendXChaCha20Poly1305OpenSSL = AEADTypeEnum{"XChaCha20-Poly1305", "OpenSSL", chacha20poly1305.NonceSizeX}

BackendXChaCha20Poly1305OpenSSL specifies XChaCha20-Poly1305-OpenSSL.

Functions

func RandBytes

func RandBytes(n int) []byte

RandBytes gets "n" random bytes from /dev/urandom or panics

func RandUint64

func RandUint64() uint64

RandUint64 returns a secure random uint64

Types

type AEADTypeEnum

type AEADTypeEnum struct {
	// Algo is the encryption algorithm. Example: "AES-GCM-256"
	Algo string
	// Lib is the library where Algo is implemented. Either "Go" or "OpenSSL".
	Lib       string
	NonceSize int
}

AEADTypeEnum indicates the type of AEAD backend in use.

func (AEADTypeEnum) String added in v2.2.1

func (a AEADTypeEnum) String() string

String returns something like "AES-GCM-256-OpenSSL"

type CryptoCore

type CryptoCore struct {
	// EME is used for filename encryption.
	EMECipher *eme.EMECipher
	// GCM or AES-SIV. This is used for content encryption.
	AEADCipher cipher.AEAD
	// Which backend is behind AEADCipher?
	AEADBackend AEADTypeEnum
	// GCM needs unique IVs (nonces)
	IVGenerator *nonceGenerator
	// IVLen in bytes
	IVLen int
}

CryptoCore is the low level crypto implementation.

func New

func New(key []byte, aeadType AEADTypeEnum, IVBitLen int, useHKDF bool) *CryptoCore

New returns a new CryptoCore object or panics.

Even though the "GCMIV128" feature flag is now mandatory, we must still support 96-bit IVs here because they were used for encrypting the master key in gocryptfs.conf up to gocryptfs v1.2. v1.3 switched to 128 bits.

Note: "key" is either the scrypt hash of the password (when decrypting a config file) or the masterkey (when finally mounting the filesystem).

func (*CryptoCore) Wipe

func (c *CryptoCore) Wipe()

Wipe tries to wipe secret keys from memory by overwriting them with zeros and/or setting references to nil.

This is not bulletproof due to possible GC copies, but still raises to bar for extracting the key.

Jump to

Keyboard shortcuts

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