Documentation
¶
Index ¶
- Constants
- Variables
- func DeriveNonceBlake3(src, out []byte)
- func ValidateKeySize(e BlockEnc, keySize int) error
- type AllocFn
- type BlockEnc
- func (x BlockEnc) Enum() *BlockEnc
- func (x BlockEnc) MarshalJSON() ([]byte, error)
- func (x BlockEnc) MarshalProtoJSON(s *json.MarshalState)
- func (x BlockEnc) MarshalProtoText() string
- func (x BlockEnc) MarshalText() ([]byte, error)
- func (x BlockEnc) String() string
- func (x *BlockEnc) UnmarshalJSON(b []byte) error
- func (x *BlockEnc) UnmarshalProtoJSON(s *json.UnmarshalState)
- func (x *BlockEnc) UnmarshalText(b []byte) error
- func (e BlockEnc) Validate() error
- type Method
Constants ¶
const BlockEnc_BlockEnc_MAX = BlockEnc_BlockEnc_SECRET_BOX
BlockEnc_BlockEnc_MAX is the maximum value for BlockCrypt.
Variables ¶
var ( BlockEnc_name = map[int32]string{ 0: "BlockEnc_UNKNOWN", 1: "BlockEnc_NONE", 2: "BlockEnc_XCHACHA20_POLY1305", 3: "BlockEnc_SECRET_BOX", } BlockEnc_value = map[string]int32{ "BlockEnc_UNKNOWN": 0, "BlockEnc_NONE": 1, "BlockEnc_XCHACHA20_POLY1305": 2, "BlockEnc_SECRET_BOX": 3, } )
Enum value maps for BlockEnc.
var BlockEnc_KeySize = map[BlockEnc]int{
BlockEnc_BlockEnc_SECRET_BOX: 32,
BlockEnc_BlockEnc_XCHACHA20_POLY1305: 32,
}
BlockEnc_KeySize is the set of known key sizes.
var ErrDecryptFail = errors.New("failed to decrypt message")
ErrDecryptFail is returned if the decrypt operation failed.
var ErrShortKey = errors.New("key too short")
ErrShortKey is returned if the key was too short.
var ErrShortMsg = errors.New("message too short")
ErrShortMsg is returned if the encrypted message was too short.
Functions ¶
func DeriveNonceBlake3 ¶
func DeriveNonceBlake3(src, out []byte)
DeriveNonceBlake3 derives a nonce using blake3 key derivation. Fills "out" with data using all of src.
func ValidateKeySize ¶
ValidateKeySize checks the given key size is the expected.
Types ¶
type AllocFn ¶
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 ¶
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 ¶
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 defaults to BlockEnc_XCHACHA20_POLY1305. 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 )
func (BlockEnc) MarshalJSON ¶
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 (BlockEnc) MarshalText ¶
MarshalText marshals the BlockEnc to text.
func (*BlockEnc) UnmarshalJSON ¶
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 ¶
UnmarshalText unmarshals the BlockEnc from text.
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 ¶
BuildBlockEnc builds block enc methods from known types.
func NewSecretBox ¶
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 ¶
NewXChaCha20Poly1305 constructs a new cipher.