Documentation ¶
Overview ¶
Package crypto provides all cryptographic operations needed in restic.
Index ¶
Constants ¶
const (
// Extension is the number of bytes a plaintext is enlarged by encrypting it.
Extension = ivSize + macSize
)
Variables ¶
var DefaultKDFParams = KDFParams{ N: sscrypt.DefaultParams.N, R: sscrypt.DefaultParams.R, P: sscrypt.DefaultParams.P, }
DefaultKDFParams are the default parameters used for Calibrate and KDF().
var ErrInvalidCiphertext = errors.New("invalid ciphertext, same slice used for plaintext")
ErrInvalidCiphertext is returned when trying to encrypt into the slice that holds the plaintext.
var ( // ErrUnauthenticated is returned when ciphertext verification has failed. ErrUnauthenticated = errors.New("ciphertext verification failed") )
Functions ¶
Types ¶
type EncryptionKey ¶
type EncryptionKey [32]byte
EncryptionKey is key used for encryption
func (*EncryptionKey) MarshalJSON ¶
func (k *EncryptionKey) MarshalJSON() ([]byte, error)
MarshalJSON converts the EncryptionKey to JSON.
func (*EncryptionKey) UnmarshalJSON ¶
func (k *EncryptionKey) UnmarshalJSON(data []byte) error
UnmarshalJSON fills the key k with data from the JSON representation.
func (*EncryptionKey) Valid ¶
func (k *EncryptionKey) Valid() bool
Valid tests whether the key k is valid (i.e. not zero).
type Key ¶
type Key struct { MACKey `json:"mac"` EncryptionKey `json:"encrypt"` }
Key holds encryption and message authentication keys for a repository. It is stored encrypted and authenticated as a JSON data structure in the Data field of the Key structure.
func KDF ¶
KDF derives encryption and message authentication keys from the password using the supplied parameters N, R and P and the Salt.
func NewRandomKey ¶
func NewRandomKey() *Key
NewRandomKey returns new encryption and message authentication keys.
func (*Key) Decrypt ¶
Decrypt verifies and decrypts the ciphertext. Ciphertext must be in the form IV || Ciphertext || MAC. plaintext and ciphertext may point to (exactly) the same slice.
type MACKey ¶
type MACKey struct { K [16]byte // for AES-128 R [16]byte // for Poly1305 // contains filtered or unexported fields }
MACKey is used to sign (authenticate) data.
func (*MACKey) MarshalJSON ¶
MarshalJSON converts the MACKey to JSON.
func (*MACKey) UnmarshalJSON ¶
UnmarshalJSON fills the key m with data from the JSON representation.