-
Notifications
You must be signed in to change notification settings - Fork 0
/
lm_opts.go
70 lines (58 loc) · 1.53 KB
/
lm_opts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package lmots
import (
"bytes"
"crypto/rand"
)
// domain separation fields enumerators indicating the message to hash
// - D_PBLC = 0x8080 when computing the hash of all of the iterates
// in the LM-OTS algorithm
// - D_MESG = 0x8181 when computing the hash of the message in the
// LM-OTS algorithms
// - D_LEAF = 0x8282 when computing the hash of the leaf of an LMS
// tree
// - D_INTR = 0x8383 when computing the hash of an interior node of
// an LMS tree
const (
D_PBLC = 0x8080
D_MESG = 0x8181
D_LEAF = 0x8282
D_INTR = 0x8383
)
const (
key_id_len = 16 // length of key pair identifier
)
// LMOpts wraps options for key generations, signing
// and verification
type LMOpts struct {
// big-endian order bytes for LMOTS_SHAKE{shake}_N{n}_W{w}
// typecodes defined in params.go
Typecode [4]byte
// key pair identifier
I [key_id_len]byte
// index of the current key pair
KeyIdx uint32
}
// NewLMOpts makes an LM-OTS option with default `typecode`
// and `keyIdx` as 0
func NewLMOpts() *LMOpts {
opts := new(LMOpts)
opts.Typecode = METAOPTS_DEFAULT.typecode
if _, err := rand.Read(opts.I[:]); nil != err {
return nil
}
opts.KeyIdx = 0
return opts
}
// Clone makes a copy of this *LMOpts
func (opts *LMOpts) Clone() *LMOpts {
optsC := *opts
return &optsC
}
// Equal checks the equality of two options
func (opts *LMOpts) Equal(rhs *LMOpts) bool {
if opts == rhs {
return true
}
return (nil != rhs) && bytes.Equal(opts.Typecode[:], rhs.Typecode[:]) &&
bytes.Equal(opts.I[:], rhs.I[:]) && (opts.KeyIdx == rhs.KeyIdx)
}