backup

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 13 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// KeyLen is the length of the backup key generated
	KeyLen = chacha20poly1305.KeySize

	// SaltLen is the required length of the salt. Recommended being set to 16
	// bytes here:
	// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-argon2-04#section-3.1
	SaltLen = 16
)
View Source
const (

	// ParamsLen is the length of the marshalled Params object.
	ParamsLen = paramTimeLen + paramMemoryLen + paramThreadsLen
)

Length of fields in the Params object.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(blob, key []byte) ([]byte, error)

func DeriveKey

func DeriveKey(password string, salt []byte, params Params) []byte

DeriveKey derives a key from a user supplied password and a salt via the Argon2 algorithm.

func Encrypt

func Encrypt(rand csprng.Source, plaintext, key []byte) ([]byte, error)

func MakeSalt

func MakeSalt(csprng csprng.Source) ([]byte, error)

MakeSalt generates a salt of the correct length of key generation.

Types

type Backup

type Backup struct {
	RegistrationTimestamp     int64                     `json:"registrationTimestamp"`
	RegistrationCode          string                    `json:"registrationCode"`
	JSONParams                string                    `json:"jsonParams"`
	TransmissionIdentity      TransmissionIdentity      `json:"transmissionIdentity"`
	ReceptionIdentity         ReceptionIdentity         `json:"receptionIdentity"`
	UserDiscoveryRegistration UserDiscoveryRegistration `json:"userDiscoveryRegistration"`
	Contacts                  Contacts                  `json:"contacts"`
}

func (*Backup) Decrypt

func (b *Backup) Decrypt(password string, blob []byte) error

Decrypt decrypts the encrypted serialized backup. Returns an error for invalid version or invalid tag.

func (*Backup) Encrypt

func (b *Backup) Encrypt(rand csprng.Source, key, salt []byte, params Params) (
	[]byte, error)

Encrypt returns the encrypted serialized backup with the format for account backups:

"XXACCTBAK" | [VERSION as 1 byte] | [salt and params] | [DATA]

The key passed in must be derived via DeriveKey and the salt must be the same used to derive the key. Key derivation happens outside the encryption because it is slow, so that the key can be stored and reused.

type Contacts

type Contacts struct {
	Identities []*id.ID `json:"identities"`
}

type Params

type Params struct {
	Time    uint32 `json:"time"`    // Number of passes over the memory
	Memory  uint32 `json:"memory"`  // Amount of memory used in KiB
	Threads uint8  `json:"threads"` // Number of threads used
}

Params contains the cost parameters used by Argon2.

func DefaultParams

func DefaultParams() Params

DefaultParams returns the recommended general purposes parameters.

func (*Params) Marshal

func (p *Params) Marshal() []byte

Marshal marshals the Params object into a byte slice.

func (*Params) Unmarshal

func (p *Params) Unmarshal(buf []byte) error

Unmarshal decodes the byte slice into a Params objects.

type ReceptionIdentity

type ReceptionIdentity struct {
	RSASigningPrivateKey *rsa.PrivateKey `json:"rsaSigningPrivateKey"`
	RegistrarSignature   []byte          `json:"registrarSignature"`
	Salt                 []byte          `json:"salt"`
	ComputedID           *id.ID          `json:"computedID"`
	DHPrivateKey         *cyclic.Int     `json:"dhPrivateKey"`
	DHPublicKey          *cyclic.Int     `json:"dhPublicKey"`
}

type TransmissionIdentity

type TransmissionIdentity struct {
	RSASigningPrivateKey *rsa.PrivateKey `json:"rsaSigningPrivateKey"`
	RegistrarSignature   []byte          `json:"registrarSignature"`
	Salt                 []byte          `json:"salt"`
	ComputedID           *id.ID          `json:"computedID"`
}

type UserDiscoveryRegistration

type UserDiscoveryRegistration struct {
	fact.FactList
}

Jump to

Keyboard shortcuts

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