go_sshkeys/kdf/types.go

34 lines
1.4 KiB
Go

package kdf
import (
"bytes"
)
// KDF is a type of KDF (Key Derivation Function).
type KDF interface {
// Name returns the string form of the KDF name.
Name() (name string)
// NameBytes returns the Name result but in bytes with a leading uint32 bytecount packed in.
NameBytes() (name []byte)
// Rounds returns the number of rounds used in derivation.
Rounds() (rounds uint32)
// Salt returns the salt bytes.
Salt() (salt []byte)
// Setup initializes the KDF with the given derivation secret (password) and KDF options.
Setup(secret, salt []byte, rounds, keyLen uint32) (err error)
// DeriveKey derives the key. Setup (or SetupAuto) must have been run first.
DeriveKey() (key []byte, err error)
// SetupAuto configures a partially reconstructed KDF options that were parsed from GetKdfFromBytes (if KDF.AutoOK returns true).
SetupAuto(secret []byte, keyLen uint32) (err error)
// AutoOK returns true if all components were able to be parsed from GetKdfFromBytes.
AutoOK() (ok bool)
// IsPlain returns true if this is a "null" kdf; i.e. no derivation is actually performed.
IsPlain() (plain bool)
// PackedBytes returns the bytes suitable for serializing into a key file.
PackedBytes() (buf *bytes.Reader, err error)
// AddSalt adds the salt as parsed from the private key.
AddSalt(salt []byte) (err error)
// AddRounds adds the rounds as parsed from the private key.
AddRounds(rounds uint32) (err error)
}