Documentation
¶
Index ¶
- Constants
- Variables
- func AddLmotsParam(typ LmotsType, fn func() ILmotsParam)
- func AddLmsParam(typ LmsType, fn func() ILmsParam)
- func AllLmotsParams() map[LmotsType]func() ILmotsParam
- func AllLmsParams() map[LmsType]func() ILmsParam
- func Cksm(coefs []uint8, w ByteWindow, LS uint64) uint16
- func Coefs(x []byte, w ByteWindow) []uint8
- func Expand(msg []byte, mode ILmotsParam) ([]uint8, error)
- func GeneratePKTree(typ ILmsParam, otsType ILmotsParam, id ID, seed []byte) ([][]byte, error)
- func GetLmotsParam(typ LmotsType) (func() ILmotsParam, error)
- func GetLmsParam(typ LmsType) (func() ILmsParam, error)
- type ByteWindow
- type HSSOpts
- type HSSPrivateKey
- func (priv *HSSPrivateKey) Equal(x crypto.PrivateKey) bool
- func (priv *HSSPrivateKey) Public() crypto.PublicKey
- func (priv *HSSPrivateKey) PublicKey() HSSPublicKey
- func (priv *HSSPrivateKey) Sign(rng io.Reader, msg []byte, _ crypto.SignerOpts) ([]byte, error)
- func (priv *HSSPrivateKey) ToBytes() ([]byte, error)
- type HSSPublicKey
- type Hasher
- type ID
- type ILmotsParam
- type ILmsParam
- type LmotsParam
- type LmotsPrivateKey
- func (priv *LmotsPrivateKey) Equal(x crypto.PrivateKey) bool
- func (priv *LmotsPrivateKey) Public() crypto.PublicKey
- func (priv *LmotsPrivateKey) PublicKey() LmotsPublicKey
- func (priv *LmotsPrivateKey) Sign(rng io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
- func (priv *LmotsPrivateKey) SignToSignature(rng io.Reader, msg []byte, opts crypto.SignerOpts) (*LmotsSignature, error)
- type LmotsPublicKey
- type LmotsSignature
- type LmotsSignerOpts
- type LmotsType
- type LmsParam
- type LmsType
- type PrivateKey
- func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool
- func (priv *PrivateKey) Precompute()
- func (priv *PrivateKey) Public() crypto.PublicKey
- func (priv *PrivateKey) Q() uint32
- func (priv *PrivateKey) Sign(rng io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
- func (priv *PrivateKey) SignToSignature(rng io.Reader, msg []byte, opts crypto.SignerOpts) (*Signature, error)
- func (priv *PrivateKey) ToBytes() []byte
- type PublicKey
- type Signature
- type SignerOpts
- type TypeDataName
- type TypeParams
Constants ¶
const ( WINDOW_W1 window = 1 << iota WINDOW_W2 WINDOW_W4 WINDOW_W8 )
const HSS_MAX_LEVELS = 5
const ID_LEN uint64 = 16
Variables ¶
var ( LMOTS_SHA256_N32_W1 = LmotsParam{ Name: "LMOTS_SHA256_N32_W1", Type: type_LMOTS_SHA256_N32_W1, Hash: sha256.New, N: sha256.Size, W: WINDOW_W1, P: 265, LS: 7, SigLen: 8516, } LMOTS_SHA256_N32_W2 = LmotsParam{ Name: "LMOTS_SHA256_N32_W2", Type: type_LMOTS_SHA256_N32_W2, Hash: sha256.New, N: sha256.Size, W: WINDOW_W2, P: 133, LS: 6, SigLen: 4292, } LMOTS_SHA256_N32_W4 = LmotsParam{ Name: "LMOTS_SHA256_N32_W4", Type: type_LMOTS_SHA256_N32_W4, Hash: sha256.New, N: sha256.Size, W: WINDOW_W4, P: 67, LS: 4, SigLen: 2180, } LMOTS_SHA256_N32_W8 = LmotsParam{ Name: "LMOTS_SHA256_N32_W8", Type: type_LMOTS_SHA256_N32_W8, Hash: sha256.New, N: sha256.Size, W: WINDOW_W8, P: 34, LS: 0, SigLen: 1124, } // SM3 hash LMOTS_SM3_N32_W1 = LmotsParam{ Name: "LMOTS_SM3_N32_W1", Type: type_LMOTS_SM3_N32_W1, Hash: sm3.New, N: sm3.Size, W: WINDOW_W1, P: 265, LS: 7, SigLen: 8516, } LMOTS_SM3_N32_W2 = LmotsParam{ Name: "LMOTS_SM3_N32_W2", Type: type_LMOTS_SM3_N32_W2, Hash: sm3.New, N: sm3.Size, W: WINDOW_W2, P: 133, LS: 6, SigLen: 4292, } LMOTS_SM3_N32_W4 = LmotsParam{ Name: "LMOTS_SM3_N32_W4", Type: type_LMOTS_SM3_N32_W4, Hash: sm3.New, N: sm3.Size, W: WINDOW_W4, P: 67, LS: 4, SigLen: 2180, } LMOTS_SM3_N32_W8 = LmotsParam{ Name: "LMOTS_SM3_N32_W8", Type: type_LMOTS_SM3_N32_W8, Hash: sm3.New, N: sm3.Size, W: WINDOW_W8, P: 34, LS: 0, SigLen: 1124, } )
var ( LMS_SHA256_M32_H5 = LmsParam{ Name: "LMS_SHA256_M32_H5", Type: type_LMS_SHA256_M32_H5, Hash: sha256.New, M: 32, H: 5, } LMS_SHA256_M32_H10 = LmsParam{ Name: "LMS_SHA256_M32_H10", Type: type_LMS_SHA256_M32_H10, Hash: sha256.New, M: 32, H: 10, } LMS_SHA256_M32_H15 = LmsParam{ Name: "LMS_SHA256_M32_H15", Type: type_LMS_SHA256_M32_H15, Hash: sha256.New, M: 32, H: 15, } LMS_SHA256_M32_H20 = LmsParam{ Name: "LMS_SHA256_M32_H20", Type: type_LMS_SHA256_M32_H20, Hash: sha256.New, M: 32, H: 20, } LMS_SHA256_M32_H25 = LmsParam{ Name: "LMS_SHA256_M32_H25", Type: type_LMS_SHA256_M32_H25, Hash: sha256.New, M: 32, H: 25, } // SM3 LMS_SM3_M32_H5 = LmsParam{ Name: "LMS_SM3_M32_H5", Type: type_LMS_SM3_M32_H5, Hash: sm3.New, M: 32, H: 5, } LMS_SM3_M32_H10 = LmsParam{ Name: "LMS_SM3_M32_H10", Type: type_LMS_SM3_M32_H10, Hash: sm3.New, M: 32, H: 10, } LMS_SM3_M32_H15 = LmsParam{ Name: "LMS_SM3_M32_H15", Type: type_LMS_SM3_M32_H15, Hash: sm3.New, M: 32, H: 15, } LMS_SM3_M32_H20 = LmsParam{ Name: "LMS_SM3_M32_H20", Type: type_LMS_SM3_M32_H20, Hash: sm3.New, M: 32, H: 20, } LMS_SM3_M32_H25 = LmsParam{ Name: "LMS_SM3_M32_H25", Type: type_LMS_SM3_M32_H25, Hash: sm3.New, M: 32, H: 25, } )
var D_INTR = [2]uint8{0x83, 0x83}
var D_LEAF = [2]uint8{0x82, 0x82}
var D_MESG = [2]uint8{0x81, 0x81}
var D_PBLC = [2]uint8{0x80, 0x80}
var DefaultLmotsSignerOpts = LmotsSignerOpts{}
default Signer Opts
var DefaultOpts = []HSSOpts{ HSSOpts{ Type: LMS_SHA256_M32_H5, OtsType: LMOTS_SHA256_N32_W8, }, HSSOpts{ Type: LMS_SHA256_M32_H5, OtsType: LMOTS_SHA256_N32_W8, }, }
Default Opts
var DefaultSignerOpts = SignerOpts{}
default Signer Opts
Functions ¶
func Cksm ¶
func Cksm(coefs []uint8, w ByteWindow, LS uint64) uint16
Returns a checksum calculated over a slice of Winternitz coefficients
func Coefs ¶
func Coefs(x []byte, w ByteWindow) []uint8
Returns a []byte representing the Winternitz coefficients of x for a given window, w
func Expand ¶
func Expand(msg []byte, mode ILmotsParam) ([]uint8, error)
expands a message into the winternitz coefficients of the message and its checksum returns a slice of length P
func GeneratePKTree ¶
GeneratePKTree generates the Merkle Tree needed to derive the public key and authentication path for any message.
Types ¶
type ByteWindow ¶
type ByteWindow interface {
Window() window
Mask() uint8
}
ByteWindow is the representation of bytes used in calculating LM-OTS signatures
type HSSPrivateKey ¶
type HSSPrivateKey struct {
HSSPublicKey
LmsKey [5]PrivateKey
LmsSig [4]Signature
}
A HSSPrivateKey is used to sign a finite number of messages
func GenerateHSSKey ¶
func GenerateHSSKey(rng io.Reader, opts []HSSOpts) (*HSSPrivateKey, error)
GenerateHSSKey returns a new HSSPrivateKey
func NewHSSPrivateKeyFromBytes ¶
func NewHSSPrivateKeyFromBytes(b []byte) (*HSSPrivateKey, error)
NewHSSPrivateKeyFromBytes returns an HSSPrivateKey that represents b.
func (*HSSPrivateKey) Equal ¶ added in v1.0.3005
func (priv *HSSPrivateKey) Equal(x crypto.PrivateKey) bool
Equal reports whether priv and x have the same value.
func (*HSSPrivateKey) Public ¶
func (priv *HSSPrivateKey) Public() crypto.PublicKey
Public returns a crypto.PublicKey that validates signatures for this private key
func (*HSSPrivateKey) PublicKey ¶ added in v1.0.3005
func (priv *HSSPrivateKey) PublicKey() HSSPublicKey
PublicKey returns a HSSPublicKey that validates signatures for this private key
func (*HSSPrivateKey) Sign ¶
func (priv *HSSPrivateKey) Sign(rng io.Reader, msg []byte, _ crypto.SignerOpts) ([]byte, error)
Sign calculates the LMS-HSS signature of a chosen message.
func (*HSSPrivateKey) ToBytes ¶
func (priv *HSSPrivateKey) ToBytes() ([]byte, error)
ToBytes() serializes the public key into a byte string for transmission or storage.
type HSSPublicKey ¶
A HSSPublicKey is used to verify messages signed by a HSSPrivateKey
func NewHSSPublicKeyFromBytes ¶
func NewHSSPublicKeyFromBytes(b []byte) (*HSSPublicKey, error)
NewHSSPublicKeyFromBytes returns an HSSPublicKey that represents b.
func (*HSSPublicKey) Equal ¶ added in v1.0.3005
func (pub *HSSPublicKey) Equal(x crypto.PublicKey) bool
Equal reports whether pub and x have the same value.
func (*HSSPublicKey) ToBytes ¶
func (pub *HSSPublicKey) ToBytes() []byte
ToBytes() serializes the public key into a byte string for transmission or storage.
type ILmotsParam ¶
type ILmotsParam interface {
GetType() LmotsType
SigLength() uint64
Params() LmotsParam
}
ILmotsParam represents a specific instance of LM-OTS
type ILmsParam ¶
type ILmsParam interface {
GetType() LmsType
SigLength(ILmotsParam) uint64
Params() LmsParam
}
ILmsParam represents a specific instance of LMS
type LmotsParam ¶
type LmotsParam struct {
Name string
Type LmotsType
Hash Hasher
N uint64
W ByteWindow
P uint64
LS uint64
SigLen uint64
}
func (LmotsParam) GetType ¶
func (this LmotsParam) GetType() LmotsType
Returns a uint32 of the same value as the LmotsType
func (LmotsParam) SigLength ¶
func (this LmotsParam) SigLength() uint64
Returns the expected byte length of a given LM-OTS signature algorithm
func (LmotsParam) String ¶ added in v1.0.3003
func (this LmotsParam) String() string
Returns a param name string
type LmotsPrivateKey ¶ added in v1.0.3003
type LmotsPrivateKey struct {
LmotsPublicKey
// contains filtered or unexported fields
}
A LmotsPrivateKey is used to sign exactly one message.
func NewLmotsPrivateKey ¶ added in v1.0.3003
func NewLmotsPrivateKey(typ ILmotsParam, q uint32, id ID) (*LmotsPrivateKey, error)
NewLmotsPrivateKey returns a LmotsPrivateKey, seeded by a cryptographically secure random number generator.
func NewLmotsPrivateKeyFromSeed ¶ added in v1.0.3003
func NewLmotsPrivateKeyFromSeed(typ ILmotsParam, q uint32, id ID, seed []byte) (*LmotsPrivateKey, error)
NewLmotsPrivateKeyFromSeed returns a new LmotsPrivateKey, using the algorithm from Appendix A of <https://datatracker.ietf.org/doc/html/rfc8554#appendix-A>
func (*LmotsPrivateKey) Equal ¶ added in v1.0.3005
func (priv *LmotsPrivateKey) Equal(x crypto.PrivateKey) bool
Equal reports whether priv and x have the same value.
func (*LmotsPrivateKey) Public ¶ added in v1.0.3003
func (priv *LmotsPrivateKey) Public() crypto.PublicKey
Public returns a crypto.PublicKey that validates signatures for this private key.
func (*LmotsPrivateKey) PublicKey ¶ added in v1.0.3005
func (priv *LmotsPrivateKey) PublicKey() LmotsPublicKey
PublicKey returns a LmotsPublicKey that validates signatures for this private key.
func (*LmotsPrivateKey) Sign ¶ added in v1.0.3003
func (priv *LmotsPrivateKey) Sign(rng io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
Sign calculates the LM-OTS signature of a chosen message.
func (*LmotsPrivateKey) SignToSignature ¶ added in v1.0.3003
func (priv *LmotsPrivateKey) SignToSignature(rng io.Reader, msg []byte, opts crypto.SignerOpts) (*LmotsSignature, error)
SignToSignature calculates the LM-OTS signature of a chosen message.
type LmotsPublicKey ¶ added in v1.0.3003
type LmotsPublicKey struct {
// contains filtered or unexported fields
}
A LmotsPublicKey is used to verify exactly one message.
func NewLmotsPublicKeyFromBytes ¶ added in v1.0.3003
func NewLmotsPublicKeyFromBytes(b []byte) (*LmotsPublicKey, error)
NewLmotsPublicKeyFromBytes returns an LmotsPublicKey that represents b. This is the inverse of the ToBytes() method on the LmotsPublicKey object.
func (*LmotsPublicKey) Equal ¶ added in v1.0.3005
func (pub *LmotsPublicKey) Equal(x crypto.PublicKey) bool
Equal reports whether pub and x have the same value.
func (*LmotsPublicKey) Key ¶ added in v1.0.3003
func (pub *LmotsPublicKey) Key() []byte
Key returns a copy of the public key's k parameter. We need this to get the public key as bytes in order to hash
func (*LmotsPublicKey) ToBytes ¶ added in v1.0.3003
func (pub *LmotsPublicKey) ToBytes() []byte
ToBytes() serializes the public key into a byte string for transmission or storage.
func (*LmotsPublicKey) Verify ¶ added in v1.0.3003
func (pub *LmotsPublicKey) Verify(msg []byte, sig []byte) bool
Verify returns true if sig is valid for msg and this public key. It returns false otherwise.
func (*LmotsPublicKey) VerifyWithSignature ¶ added in v1.0.3003
func (pub *LmotsPublicKey) VerifyWithSignature(msg []byte, sig *LmotsSignature) bool
VerifyWithSignature returns true if sig is valid for msg and this public key. It returns false otherwise.
type LmotsSignature ¶ added in v1.0.3003
type LmotsSignature struct {
// contains filtered or unexported fields
}
A LmotsSignature is a signature of one message.
func NewLmotsSignatureFromBytes ¶ added in v1.0.3003
func NewLmotsSignatureFromBytes(b []byte) (*LmotsSignature, error)
NewLmotsSignatureFromBytes returns an LmotsSignature represented by b.
func (*LmotsSignature) C ¶ added in v1.0.3003
func (sig *LmotsSignature) C() []byte
C returns a bytes for c
func (*LmotsSignature) RecoverPublicKey ¶ added in v1.0.3003
func (sig *LmotsSignature) RecoverPublicKey(msg []byte, typ ILmotsParam, id ID, q uint32) (*LmotsPublicKey, bool)
RecoverPublicKey calculates the public key for a given message. This is used in signature verification.
func (*LmotsSignature) ToBytes ¶ added in v1.0.3003
func (sig *LmotsSignature) ToBytes() ([]byte, error)
ToBytes() serializes the LM-OTS signature into a byte string for transmission or storage.
type LmotsSignerOpts ¶ added in v1.0.3003
type LmotsSignerOpts struct {
C []byte
}
Signer Opts
func (LmotsSignerOpts) HashFunc ¶ added in v1.0.3003
func (this LmotsSignerOpts) HashFunc() crypto.Hash
type LmsParam ¶
func (LmsParam) SigLength ¶
func (this LmsParam) SigLength(otstc ILmotsParam) uint64
Returns the expected byte length of a given LMS signature algorithm
type PrivateKey ¶
type PrivateKey struct {
PublicKey
// contains filtered or unexported fields
}
A PrivateKey is used to sign a finite number of messages
func GenerateKey ¶
func GenerateKey(rng io.Reader, typ ILmsParam, otsType ILmotsParam) (*PrivateKey, error)
GenerateKey returns a PrivateKey, seeded by a cryptographically secure random number generator.
func GenerateKeyFromSeed ¶
func GenerateKeyFromSeed(typ ILmsParam, otsType ILmotsParam, id ID, seed []byte) (*PrivateKey, error)
GenerateKeyFromSeed returns a new PrivateKey, using the algorithm from Appendix A of <https://datatracker.ietf.org/doc/html/rfc8554#appendix-A>
func NewPrivateKeyFromBytes ¶
func NewPrivateKeyFromBytes(b []byte) (*PrivateKey, error)
NewPrivateKeyFromBytes returns an PrivateKey that represents b. This is the inverse of the ToBytes() method on the PrivateKey object.
func (*PrivateKey) Equal ¶ added in v1.0.3005
func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool
Equal reports whether priv and x have the same value.
func (*PrivateKey) Precompute ¶ added in v1.0.3005
func (priv *PrivateKey) Precompute()
compute authtree
func (*PrivateKey) Public ¶
func (priv *PrivateKey) Public() crypto.PublicKey
Public returns an PublicKey that validates signatures for this private key
func (*PrivateKey) Q ¶
func (priv *PrivateKey) Q() uint32
Retrieve the current value of the internal counter, q. Used for unit tests
func (*PrivateKey) Sign ¶
func (priv *PrivateKey) Sign(rng io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
Sign calculates the LMS signature of a chosen message.
func (*PrivateKey) SignToSignature ¶
func (priv *PrivateKey) SignToSignature(rng io.Reader, msg []byte, opts crypto.SignerOpts) (*Signature, error)
SignToSignature calculates the LMS signature of a chosen message.
func (*PrivateKey) ToBytes ¶
func (priv *PrivateKey) ToBytes() []byte
ToBytes() serialized the private key into a byte string for storage. The current value of the internal counter, q, is included.
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
A PublicKey is used to verify messages signed by a PrivateKey
func NewPublicKey ¶
NewPublicKey return a new PublicKey, given the LMS typecode, LM-OTS typecode, ID, and root of the authentication tree (called k).
func NewPublicKeyFromBytes ¶
NewPublicKeyFromBytes returns an PublicKey that represents b. This is the inverse of the ToBytes() method on the PublicKey object.
func (*PublicKey) Key ¶
Return a []byte representing the actual public key, k, which is the root of the authentication path in the corresponding private key. We need this to get the public key as bytes in order to test
func (*PublicKey) ToBytes ¶
ToBytes() serializes the public key into a byte string for transmission or storage.
type Signature ¶
type Signature struct {
// contains filtered or unexported fields
}
A Signature represents a signature produced by an PrivateKey which an PublicKey can validate for a given message
func NewSignature ¶
NewSignature returns a Signature, given an LMS algorithm type, internal counter, LM-OTS signature, and authentication path.
func NewSignatureFromBytes ¶
NewSignatureFromBytes returns an Signature represented by b. This is the inverse of the ToBytes() on Signature.
type SignerOpts ¶
type SignerOpts struct {
C []byte
}
Signer Opts
func (SignerOpts) HashFunc ¶
func (this SignerOpts) HashFunc() crypto.Hash
type TypeParams ¶
type TypeParams[N TypeDataName, M any] struct { // contains filtered or unexported fields }
TypeParams
func NewTypeParams ¶
func NewTypeParams[N TypeDataName, M any]() *TypeParams[N, M]
func (*TypeParams[N, M]) AddParam ¶
func (this *TypeParams[N, M]) AddParam(typ N, fn func() M)
AddParam
func (*TypeParams[N, M]) AllParams ¶
func (this *TypeParams[N, M]) AllParams() map[N]func() M
AllParams
func (*TypeParams[N, M]) GetParam ¶
func (this *TypeParams[N, M]) GetParam(typ N) (func() M, error)
GetParam