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 = Params{ 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 ¶
func NewRandomNonce ¶ added in v0.8.0
func NewRandomNonce() []byte
NewRandomNonce returns a new random nonce. It panics on error so that the program is safely terminated.
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) NonceSize ¶ added in v0.8.0
NonceSize returns the size of the nonce that must be passed to Seal and Open.
func (*Key) Open ¶ added in v0.8.0
Open decrypts and authenticates ciphertext, authenticates the additional data and, if successful, appends the resulting plaintext to dst, returning the updated slice. The nonce must be NonceSize() bytes long and both it and the additional data must match the value passed to Seal.
The ciphertext and dst may alias exactly or not at all. To reuse ciphertext's storage for the decrypted output, use ciphertext[:0] as dst.
Even if the function fails, the contents of dst, up to its capacity, may be overwritten.
func (*Key) Overhead ¶ added in v0.8.0
Overhead returns the maximum difference between the lengths of a plaintext and its ciphertext.
func (*Key) Seal ¶ added in v0.8.0
Seal encrypts and authenticates plaintext, authenticates the additional data and appends the result to dst, returning the updated slice. The nonce must be NonceSize() bytes long and unique for all time, for a given key.
The plaintext and dst may alias exactly or not at all. To reuse plaintext's storage for the encrypted output, use plaintext[:0] as dst.
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.