blockenc

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBlockEnc is the encryption method used by new block transforms.
	DefaultBlockEnc = BlockEnc_BlockEnc_AES_256_GCM
	// BlockEnc_BlockEnc_MAX is the maximum value for BlockCrypt.
	BlockEnc_BlockEnc_MAX = BlockEnc_BlockEnc_AES_256_GCM
)

Variables

View Source
var (
	BlockEnc_name = map[int32]string{
		0: "BlockEnc_UNKNOWN",
		1: "BlockEnc_NONE",
		2: "BlockEnc_XCHACHA20_POLY1305",
		3: "BlockEnc_SECRET_BOX",
		4: "BlockEnc_AES_256_GCM",
	}
	BlockEnc_value = map[string]int32{
		"BlockEnc_UNKNOWN":            0,
		"BlockEnc_NONE":               1,
		"BlockEnc_XCHACHA20_POLY1305": 2,
		"BlockEnc_SECRET_BOX":         3,
		"BlockEnc_AES_256_GCM":        4,
	}
)

Enum value maps for BlockEnc.

View Source
var BlockEnc_KeySize = map[BlockEnc]int{
	BlockEnc_BlockEnc_AES_256_GCM:        32,
	BlockEnc_BlockEnc_SECRET_BOX:         32,
	BlockEnc_BlockEnc_XCHACHA20_POLY1305: 32,
}

BlockEnc_KeySize is the set of known key sizes.

View Source
var ErrDecryptFail = errors.New("failed to decrypt message")

ErrDecryptFail is returned if the decrypt operation failed.

View Source
var ErrShortKey = errors.New("key too short")

ErrShortKey is returned if the key was too short.

View Source
var ErrShortMsg = errors.New("message too short")

ErrShortMsg is returned if the encrypted message was too short.

Functions

func DeriveKeySHA256 added in v0.52.0

func DeriveKeySHA256(context string, src, out []byte)

DeriveKeySHA256 derives bytes from a context and source using SHA256.

func DeriveNonceBlake3

func DeriveNonceBlake3(src, out []byte)

DeriveNonceBlake3 derives a nonce using blake3 key derivation. Fills "out" with data using all of src.

func DeriveNonceSHA256 added in v0.52.0

func DeriveNonceSHA256(src, out []byte)

DeriveNonceSHA256 derives a nonce using SHA256. Fills "out" with data using all of src.

func ValidateKeySize

func ValidateKeySize(e BlockEnc, keySize int) error

ValidateKeySize checks the given key size is the expected.

Types

type AllocFn

type AllocFn func(n int) []byte

AllocFn allocates a buffer for use. The cap of the slice must be at least n. This can be backed by an in-memory arena.

func CheckAllocFn

func CheckAllocFn(allocFn AllocFn) AllocFn

CheckAllocFn wraps an alloc function to check the result. If the result is invalid, allocates a new buf in memory.

func DefaultAllocFn

func DefaultAllocFn() AllocFn

DefaultAllocFn constructs the default allocate func.

func NewPoolAlloc

func NewPoolAlloc() (allocFn AllocFn, relBuf func(b []byte))

NewPoolAlloc constructs a new pool alloc fn. call relBuf with the buffer when done. don't read or write to the buffer after calling relBuf.

type BlockEnc

type BlockEnc int32

BlockEnc is the block encryption method to use. Most methods use 32 byte keys.

const (
	// BlockEnc_UNKNOWN is reserved for unset configuration.
	BlockEnc_BlockEnc_UNKNOWN BlockEnc = 0
	// BlockEnc_NONE is unencrypted.
	BlockEnc_BlockEnc_NONE BlockEnc = 1
	// BlockEnc_XCHACHA20_POLY1305 uses extended chacha encryption.
	// Key size of 32 bytes.
	// Derives the nonce with blake3 key derivation.
	// Stores the nonce in the first 24 bytes of the ciphertext.
	BlockEnc_BlockEnc_XCHACHA20_POLY1305 BlockEnc = 2
	// BlockCrypt_SECRET_BOX uses nacl secret box encryption.
	// Key size of 32 bytes.
	// Derives the nonce with blake3 key derivation.
	// Stores the nonce in the first 24 bytes of the ciphertext.
	BlockEnc_BlockEnc_SECRET_BOX BlockEnc = 3
	// BlockEnc_AES_256_GCM uses AES-256-GCM encryption.
	// Key size of 32 bytes.
	// Derives the nonce with SHA256.
	// Stores the nonce in the first 12 bytes of the ciphertext.
	BlockEnc_BlockEnc_AES_256_GCM BlockEnc = 4
)

func (BlockEnc) Enum

func (x BlockEnc) Enum() *BlockEnc

func (BlockEnc) MarshalJSON

func (x BlockEnc) MarshalJSON() ([]byte, error)

MarshalJSON marshals the BlockEnc to JSON.

func (BlockEnc) MarshalProtoJSON

func (x BlockEnc) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the BlockEnc to JSON.

func (BlockEnc) MarshalProtoText

func (x BlockEnc) MarshalProtoText() string

func (BlockEnc) MarshalText

func (x BlockEnc) MarshalText() ([]byte, error)

MarshalText marshals the BlockEnc to text.

func (BlockEnc) String

func (x BlockEnc) String() string

func (*BlockEnc) UnmarshalJSON

func (x *BlockEnc) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the BlockEnc from JSON.

func (*BlockEnc) UnmarshalProtoJSON

func (x *BlockEnc) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the BlockEnc from JSON.

func (*BlockEnc) UnmarshalText

func (x *BlockEnc) UnmarshalText(b []byte) error

UnmarshalText unmarshals the BlockEnc from text.

func (BlockEnc) Validate

func (e BlockEnc) Validate() error

Validate checks if the blockenc is in the known set.

type Method

type Method interface {
	// Encrypt encrypts the block and returns the encrypted buf.
	Encrypt(alloc AllocFn, src []byte) ([]byte, error)
	// Decrypt decrypts the whole block and returns the decrypted buf.
	Decrypt(alloc AllocFn, src []byte) ([]byte, error)
}

Method is a block encryption method. do not write to src

func BuildBlockEnc

func BuildBlockEnc(enc BlockEnc, key []byte) (Method, error)

BuildBlockEnc builds block enc methods from known types.

func NewAES256GCM added in v0.52.0

func NewAES256GCM(key []byte) (Method, error)

NewAES256GCM constructs a new AES-256-GCM block encryption method.

func NewNoop

func NewNoop() Method

NewNoop constructs a new no-op method.

func NewSecretBox

func NewSecretBox(key []byte) (Method, error)

NewSecretBox constructs a new nacl scret box method.

The first 24 bytes of the encrypted block are the nonce. Nonce is derived from the blake3 keyderiv of the source.

func NewXChaCha20Poly1305

func NewXChaCha20Poly1305(key []byte) (Method, error)

NewXChaCha20Poly1305 constructs a new cipher.

type NonceDeriver added in v0.52.0

type NonceDeriver func(src, out []byte)

NonceDeriver derives a deterministic nonce for an encrypted block body.

Jump to

Keyboard shortcuts

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