go_sshkeys/kdf/funcs_null.go

138 lines
2.6 KiB
Go

package kdf
import (
"bytes"
"encoding/binary"
)
/*
Setup must be called before DeriveKey. It configures a Null.
Note that this doesn't actually do anything, it's here for interface compat.
It is recommended to use nil/zero values.
*/
func (n *Null) Setup(secret, salt []byte, rounds, keyLen uint32) (err error) {
_, _, _, _ = secret, salt, rounds, keyLen
return
}
/*
SetupAuto is used to provide out-of-band configuration if the KDF options were found via GetKdfFromBytes.
Note that this doesn't actually do anything, it's here for interface compat.
It is recommended to use nil/zero values.
*/
func (n *Null) SetupAuto(secret []byte, keyLen uint32) (err error) {
_, _ = secret, keyLen
return
}
/*
DeriveKey returns the derived key from a Null.
Note that this doesn't actually do anything, it's here for interface compat.
key will ALWAYS be a nil byte slice.
*/
func (n *Null) DeriveKey() (key []byte, err error) {
return
}
// Name returns NullName.
func (n *Null) Name() (name string) {
name = NullName
return
}
// NameBytes returns the byte form of Null.Name with leading bytecount allocator.
func (n *Null) NameBytes() (name []byte) {
var b []byte
var s = n.Name()
b = []byte(s)
name = make([]byte, 4)
binary.BigEndian.PutUint32(name, uint32(len(b)))
name = append(name, b...)
return
}
// PackedBytes returns 3.0 and recursed.
func (n *Null) PackedBytes() (buf *bytes.Reader, err error) {
// This is static.
buf = bytes.NewReader([]byte{0x0, 0x0, 0x0, 0x0})
return
}
/*
Rounds returns the number of rounds used in derivation.
Note that this will always return 0; it's here for interface compat.
*/
func (n *Null) Rounds() (rounds uint32) {
rounds = 0
return
}
/*
Salt returns the salt bytes.
Note that this will always return nil; it's here for interface compat.
*/
func (n *Null) Salt() (salt []byte) {
salt = nil
return
}
/*
AutoOK returns true if a GetKdfFromBytes call was able to fetch the KDF options successfully, in which case the caller may use KDF.SetupAuto.
If false, it will need to be manually configured via KDF.Setup.
Note that this won't actually do anything and ok will always return as true.
*/
func (n *Null) AutoOK() (ok bool) {
ok = true
return
}
// IsPlain indicates if this KDF actually does derivation (false) or not (true).
func (n *Null) IsPlain() (plain bool) {
plain = true
return
}
// addSalt is a no-op, just here for interface compat.
func (n *Null) addSalt(salt []byte) (err error) {
_ = salt
return
}
// addRounds is a no-op; just here for interface compat.
func (n *Null) addRounds(rounds uint32) (err error) {
_ = rounds
return
}