-
Notifications
You must be signed in to change notification settings - Fork 5
/
params.go
633 lines (568 loc) · 18.6 KB
/
params.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
//go:generate enumer -type HashFunc
package xmssmt
import (
"encoding/binary"
"fmt"
"reflect"
"strconv"
"strings"
)
// Hash function to use.
type HashFunc uint8
const (
// SHA-256 for n≤32 and SHA-512 otherwise. (From the RFC.)
SHA2 HashFunc = iota
// SHAKE-128 for n≤32 and SHAKE-256 otherwise. (From the RFC.)
SHAKE
// SHAKE-256. (From NIST SP 800-208.)
SHAKE256
)
// Way to construct the various PRFs from the hash function.
type PrfConstruction uint8
const (
// As described by RFC8391.
RFC PrfConstruction = iota
// As described by NIST SP 800-208.
NIST
)
// Parameters of an XMSS[MT] instance
type Params struct {
Func HashFunc // which has function to use
N uint32 // security parameter: influences length of hashes
FullHeight uint32 // full height of tree
D uint32 // number of subtrees; 1 for XMSS, >1 for XMSSMT
// WOTS+ Winternitz parameter. Only 4, 16 and 256 are supported.
WotsW uint16
// Method to use for construction of the PRFs.
Prf PrfConstruction
}
func (p Params) String() string {
wString := ""
prfString := ""
if p.Prf == NIST && p.N != 24 {
prfString = "_NIST"
}
if p.Prf == RFC && p.N == 24 {
prfString = "_RFC"
}
if p.WotsW != 16 {
wString = fmt.Sprintf("_w%d", p.WotsW)
}
if p.D == 1 {
return fmt.Sprintf("XMSS-%s_%d_%d%s%s",
p.Func, p.FullHeight, p.N*8, wString, prfString)
}
return fmt.Sprintf("XMSSMT-%s_%d/%d_%d%s%s",
p.Func, p.FullHeight, p.D, p.N*8, wString, prfString)
}
// Registry of named XMSS[MT] algorithms
var registry []regEntry = []regEntry{
// From RFC8391.
{"XMSSMT-SHA2_20/2_256", true, 0x00000001, Params{SHA2, 32, 20, 2, 16, RFC}},
{"XMSSMT-SHA2_20/4_256", true, 0x00000002, Params{SHA2, 32, 20, 4, 16, RFC}},
{"XMSSMT-SHA2_40/2_256", true, 0x00000003, Params{SHA2, 32, 40, 2, 16, RFC}},
{"XMSSMT-SHA2_40/4_256", true, 0x00000004, Params{SHA2, 32, 40, 4, 16, RFC}},
{"XMSSMT-SHA2_40/8_256", true, 0x00000005, Params{SHA2, 32, 40, 8, 16, RFC}},
{"XMSSMT-SHA2_60/3_256", true, 0x00000006, Params{SHA2, 32, 60, 3, 16, RFC}},
{"XMSSMT-SHA2_60/6_256", true, 0x00000007, Params{SHA2, 32, 60, 6, 16, RFC}},
{"XMSSMT-SHA2_60/12_256", true, 0x00000008, Params{SHA2, 32, 60, 12, 16, RFC}},
{"XMSSMT-SHA2_20/2_512", true, 0x00000009, Params{SHA2, 64, 20, 2, 16, RFC}},
{"XMSSMT-SHA2_20/4_512", true, 0x0000000a, Params{SHA2, 64, 20, 4, 16, RFC}},
{"XMSSMT-SHA2_40/2_512", true, 0x0000000b, Params{SHA2, 64, 40, 2, 16, RFC}},
{"XMSSMT-SHA2_40/4_512", true, 0x0000000c, Params{SHA2, 64, 40, 4, 16, RFC}},
{"XMSSMT-SHA2_40/8_512", true, 0x0000000d, Params{SHA2, 64, 40, 8, 16, RFC}},
{"XMSSMT-SHA2_60/3_512", true, 0x0000000e, Params{SHA2, 64, 60, 3, 16, RFC}},
{"XMSSMT-SHA2_60/6_512", true, 0x0000000f, Params{SHA2, 64, 60, 6, 16, RFC}},
{"XMSSMT-SHA2_60/12_512", true, 0x00000010, Params{SHA2, 64, 60, 12, 16, RFC}},
{"XMSSMT-SHAKE_20/2_256", true, 0x00000011, Params{SHAKE, 32, 20, 2, 16, RFC}},
{"XMSSMT-SHAKE_20/4_256", true, 0x00000012, Params{SHAKE, 32, 20, 4, 16, RFC}},
{"XMSSMT-SHAKE_40/2_256", true, 0x00000013, Params{SHAKE, 32, 40, 2, 16, RFC}},
{"XMSSMT-SHAKE_40/4_256", true, 0x00000014, Params{SHAKE, 32, 40, 4, 16, RFC}},
{"XMSSMT-SHAKE_40/8_256", true, 0x00000015, Params{SHAKE, 32, 40, 8, 16, RFC}},
{"XMSSMT-SHAKE_60/3_256", true, 0x00000016, Params{SHAKE, 32, 60, 3, 16, RFC}},
{"XMSSMT-SHAKE_60/6_256", true, 0x00000017, Params{SHAKE, 32, 60, 6, 16, RFC}},
{"XMSSMT-SHAKE_60/12_256", true, 0x00000018, Params{SHAKE, 32, 60, 12, 16, RFC}},
{"XMSSMT-SHAKE_20/2_512", true, 0x00000019, Params{SHAKE, 64, 20, 2, 16, RFC}},
{"XMSSMT-SHAKE_20/4_512", true, 0x0000001a, Params{SHAKE, 64, 20, 4, 16, RFC}},
{"XMSSMT-SHAKE_40/2_512", true, 0x0000001b, Params{SHAKE, 64, 40, 2, 16, RFC}},
{"XMSSMT-SHAKE_40/4_512", true, 0x0000001c, Params{SHAKE, 64, 40, 4, 16, RFC}},
{"XMSSMT-SHAKE_40/8_512", true, 0x0000001d, Params{SHAKE, 64, 40, 8, 16, RFC}},
{"XMSSMT-SHAKE_60/3_512", true, 0x0000001e, Params{SHAKE, 64, 60, 3, 16, RFC}},
{"XMSSMT-SHAKE_60/6_512", true, 0x0000001f, Params{SHAKE, 64, 60, 6, 16, RFC}},
{"XMSSMT-SHAKE_60/12_512", true, 0x00000020, Params{SHAKE, 64, 60, 12, 16, RFC}},
// From NIST SP 800-208.
{"XMSSMT-SHA2_20/2_192", true, 0x00000021, Params{SHA2, 24, 20, 2, 16, NIST}},
{"XMSSMT-SHA2_20/4_192", true, 0x00000022, Params{SHA2, 24, 20, 4, 16, NIST}},
{"XMSSMT-SHA2_40/2_192", true, 0x00000023, Params{SHA2, 24, 40, 2, 16, NIST}},
{"XMSSMT-SHA2_40/4_192", true, 0x00000024, Params{SHA2, 24, 40, 4, 16, NIST}},
{"XMSSMT-SHA2_40/8_192", true, 0x00000025, Params{SHA2, 24, 40, 8, 16, NIST}},
{"XMSSMT-SHA2_60/3_192", true, 0x00000026, Params{SHA2, 24, 60, 3, 16, NIST}},
{"XMSSMT-SHA2_60/6_192", true, 0x00000027, Params{SHA2, 24, 60, 6, 16, NIST}},
{"XMSSMT-SHA2_60/12_192", true, 0x00000028, Params{SHA2, 24, 60, 12, 16, NIST}},
{"XMSSMT-SHAKE256_20/2_256", true, 0x00000029, Params{SHAKE256, 32, 20, 2, 16, RFC}},
{"XMSSMT-SHAKE256_20/4_256", true, 0x0000002a, Params{SHAKE256, 32, 20, 4, 16, RFC}},
{"XMSSMT-SHAKE256_40/2_256", true, 0x0000002b, Params{SHAKE256, 32, 40, 2, 16, RFC}},
{"XMSSMT-SHAKE256_40/4_256", true, 0x0000002c, Params{SHAKE256, 32, 40, 4, 16, RFC}},
{"XMSSMT-SHAKE256_40/8_256", true, 0x0000002d, Params{SHAKE256, 32, 40, 8, 16, RFC}},
{"XMSSMT-SHAKE256_60/3_256", true, 0x0000002e, Params{SHAKE256, 32, 60, 3, 16, RFC}},
{"XMSSMT-SHAKE256_60/6_256", true, 0x0000002f, Params{SHAKE256, 32, 60, 6, 16, RFC}},
{"XMSSMT-SHAKE256_60/12_256", true, 0x00000030, Params{SHAKE256, 32, 60, 12, 16, RFC}},
{"XMSSMT-SHAKE256_20/2_192", true, 0x00000031, Params{SHAKE256, 24, 20, 2, 16, NIST}},
{"XMSSMT-SHAKE256_20/4_192", true, 0x00000032, Params{SHAKE256, 24, 20, 4, 16, NIST}},
{"XMSSMT-SHAKE256_40/2_192", true, 0x00000033, Params{SHAKE256, 24, 40, 2, 16, NIST}},
{"XMSSMT-SHAKE256_40/4_192", true, 0x00000034, Params{SHAKE256, 24, 40, 4, 16, NIST}},
{"XMSSMT-SHAKE256_40/8_192", true, 0x00000035, Params{SHAKE256, 24, 40, 8, 16, NIST}},
{"XMSSMT-SHAKE256_60/3_192", true, 0x00000036, Params{SHAKE256, 24, 60, 3, 16, NIST}},
{"XMSSMT-SHAKE256_60/6_192", true, 0x00000037, Params{SHAKE256, 24, 60, 6, 16, NIST}},
{"XMSSMT-SHAKE256_60/12_192", true, 0x00000038, Params{SHAKE256, 24, 60, 12, 16, NIST}},
// From RFC8391.
{"XMSS-SHA2_10_256", false, 0x00000001, Params{SHA2, 32, 10, 1, 16, RFC}},
{"XMSS-SHA2_16_256", false, 0x00000002, Params{SHA2, 32, 16, 1, 16, RFC}},
{"XMSS-SHA2_20_256", false, 0x00000003, Params{SHA2, 32, 20, 1, 16, RFC}},
{"XMSS-SHA2_10_512", false, 0x00000004, Params{SHA2, 64, 10, 1, 16, RFC}},
{"XMSS-SHA2_16_512", false, 0x00000005, Params{SHA2, 64, 16, 1, 16, RFC}},
{"XMSS-SHA2_20_512", false, 0x00000006, Params{SHA2, 64, 20, 1, 16, RFC}},
{"XMSS-SHAKE_10_256", false, 0x00000007, Params{SHAKE, 32, 10, 1, 16, RFC}},
{"XMSS-SHAKE_16_256", false, 0x00000008, Params{SHAKE, 32, 16, 1, 16, RFC}},
{"XMSS-SHAKE_20_256", false, 0x00000009, Params{SHAKE, 32, 20, 1, 16, RFC}},
{"XMSS-SHAKE_10_512", false, 0x0000000a, Params{SHAKE, 64, 10, 1, 16, RFC}},
{"XMSS-SHAKE_16_512", false, 0x0000000b, Params{SHAKE, 64, 16, 1, 16, RFC}},
{"XMSS-SHAKE_20_512", false, 0x0000000c, Params{SHAKE, 64, 20, 1, 16, RFC}},
// From NIST SP 800-208.
{"XMSS-SHA2_10_192", false, 0x0000000d, Params{SHA2, 24, 10, 1, 16, NIST}},
{"XMSS-SHA2_16_192", false, 0x0000000e, Params{SHA2, 24, 16, 1, 16, NIST}},
{"XMSS-SHA2_20_192", false, 0x0000000f, Params{SHA2, 24, 20, 1, 16, NIST}},
{"XMSS-SHAKE256_10_256", false, 0x00000010, Params{SHAKE256, 32, 10, 1, 16, RFC}},
{"XMSS-SHAKE256_16_256", false, 0x00000011, Params{SHAKE256, 32, 16, 1, 16, RFC}},
{"XMSS-SHAKE256_20_256", false, 0x00000012, Params{SHAKE256, 32, 20, 1, 16, RFC}},
{"XMSS-SHAKE256_10_192", false, 0x00000013, Params{SHAKE256, 24, 10, 1, 16, NIST}},
{"XMSS-SHAKE256_16_192", false, 0x00000014, Params{SHAKE256, 24, 16, 1, 16, NIST}},
{"XMSS-SHAKE256_20_192", false, 0x00000015, Params{SHAKE256, 24, 20, 1, 16, NIST}},
}
// Encodes parameters in the reserved Oid space as follows (big endian).
//
// 8-bit magic should be 0xEA
// 3-bit version should be 0
// 1-bit prf 0 for RFC and 1 for NIST
// 4-bit compr-n contains (n/8)-1 for the parameter n
// 2-bit hash the hash function
// 2-bit w 0 for WotsW=4, 1 for WotsW=16, 2 for WotsW=256
// 6-bit full-height the full height parameter
// 6-bit d the parameter d
//
// We assume XMSS if d == 1 and XMSSMT otherwise.
func (params *Params) MarshalBinary() ([]byte, error) {
ret := make([]byte, 4)
err := params.WriteInto(ret)
if err != nil {
return nil, err
}
return ret, nil
}
// Write parameters into buf as encoded by MarshalBinary().
func (params *Params) WriteInto(buf []byte) error {
var val uint32
var wCode uint32
var prfCode uint32
if params.N%8 != 0 {
return errorf("N is not divisable by 8")
}
if params.N > 128 {
return errorf("N is too large")
}
if params.Func > 2 {
return errorf("Func is too large")
}
if params.FullHeight > 63 {
return errorf("FullHeight is too large")
}
if params.D > 63 {
return errorf("D is too large")
}
switch params.Prf {
case RFC:
prfCode = 0
case NIST:
prfCode = 1
default:
return errorf("Unknown Prf")
}
switch params.WotsW {
case 4:
wCode = 0
case 16:
wCode = 1
case 256:
wCode = 2
default:
return errorf("Only WotsW=4,16,256 are supported")
}
val |= 0xea << 24 // magic
val |= prfCode << 20
val |= ((params.N / 8) - 1) << 16
val |= uint32(params.Func) << 14
val |= wCode << 12
val |= params.FullHeight << 6
val |= params.D
binary.BigEndian.PutUint32(buf, val)
return nil
}
// Decodes parameters as encoded by MarshalBinary().
func (params *Params) UnmarshalBinary(buf []byte) error {
if len(buf) != 4 {
return errorf("Must be 4 bytes long (instead of %d)", len(buf))
}
val := binary.BigEndian.Uint32(buf)
magic := val >> 24
if magic != 0xea {
return errorf("These are not compressed parameters (magic is wrong).")
}
version := (val >> 21) & ((1 << 3) - 1)
if version != 0 {
return errorf("Unsupported compressed parameters version")
}
comprN := (val >> 16) & ((1 << 4) - 1)
wCode := (val >> 12) & ((1 << 2) - 1)
rfcCode := (val >> 20) & 1
switch wCode {
case 0:
params.WotsW = 4
case 1:
params.WotsW = 16
case 2:
params.WotsW = 256
default:
return errorf("Unsupported W-code in compressed parameters")
}
if rfcCode == 0 {
params.Prf = RFC
} else {
params.Prf = NIST
}
params.N = (comprN + 1) * 8
params.Func = HashFunc((val >> 14) & ((1 << 2) - 1))
params.FullHeight = (val >> 6) & ((1 << 6) - 1)
params.D = val & ((1 << 6) - 1)
return nil
}
// Returns the size of the subtrees for this parameter.
func (params *Params) BareSubTreeSize() int {
height := (params.FullHeight / params.D) + 1
return int(((1 << height) - 1) * params.N)
}
// Returns the size of the cached subtrees for this parameter.
func (params *Params) CachedSubTreeSize() int {
// A cached subtree contains the merkle subtree,
// space for a WOTS+ signature of the substree above it (if it's not
// the root) and a 64bit checksum.
return params.BareSubTreeSize() + int(params.WotsSignatureSize()) + 8
}
// Size of the private key as stored by PrivateKeyContainer.
// NOTE this is not equal to the privateKeySize of the spec, which includes
// the signature sequence number, OID and root
func (params *Params) PrivateKeySize() int {
return int(params.N * 3) // skSeed + skPrf + pubSeed
}
// Entry in the registry of algorithms
type regEntry struct {
name string // name, eg. XMSSMT-SHA2_20/2_256
mt bool // whether its XMSSMT (instead of XMSS)
oid uint32 // oid of the algorithm
params Params // parameters of the algorithm
}
// Returns parameters for a named XMSS[MT] instance (and nil if there is no
// such algorithm listed in the RFC.)
func ParamsFromName(name string) *Params {
entry, ok := registryNameLut[name]
if ok {
return &entry.params
} else {
return nil
}
}
// Returns parameters for a XMSS[MT] instance (which might not be listed in
// the RFC.)
func ParamsFromName2(name string) (*Params, Error) {
ret := ParamsFromName(name)
if ret != nil {
return ret, nil
}
return parseParamsFromName(name)
}
func parseParamsFromName(name string) (*Params, Error) {
var ret Params
var mt bool
var err error
bits := strings.SplitN(name, "-", 2)
if len(bits) != 2 {
return nil, errorf("Missing seperator between alg and params")
}
switch bits[0] {
case "XMSS":
mt = false
case "XMSSMT":
mt = true
default:
return nil, errorf("No such algorithm: %s", bits[0])
}
bits = strings.Split(bits[1], "_")
switch bits[0] {
case "SHA2":
ret.Func = SHA2
case "SHAKE":
ret.Func = SHAKE
case "SHAKE256":
ret.Func = SHAKE256
default:
return nil, errorf("No such hash function: %s", bits[0])
}
if len(bits) < 3 || len(bits) > 5 {
return nil, errorf("Expected three, four or five parameters, not %d",
len(bits))
}
var unparsedFh string
if strings.Contains(bits[1], "/") {
if !mt {
return nil, errorf("Can't have D parameter for XMSS")
}
fh_d := strings.SplitN(bits[1], "/", 2)
unparsedFh = fh_d[0]
d, err := strconv.Atoi(fh_d[1])
if err != nil {
return nil, wrapErrorf(err, "Can't parse D")
}
if d < 0 || int64(d) >= int64(1)<<32 {
return nil, errorf("D out of bounds")
}
ret.D = uint32(d)
} else {
if mt {
return nil, errorf("Missing D parameter")
}
unparsedFh = bits[1]
ret.D = 1
}
fh, err := strconv.Atoi(unparsedFh)
if err != nil {
return nil, wrapErrorf(err, "Can't parse FullHeight")
}
if fh < 0 || int64(fh) >= int64(1)<<32 {
return nil, errorf("FullHeight out of bounds")
}
ret.FullHeight = uint32(fh)
n, err := strconv.Atoi(bits[2])
if err != nil {
return nil, wrapErrorf(err, "parse N")
}
if n < 0 || int64(n) > int64(1)<<32 {
return nil, errorf("N out of bounds")
}
ret.N = uint32(n) / 8
if ret.N == 24 {
ret.Prf = NIST
}
ret.WotsW = 16
for i := 3; i < len(bits); i++ {
if bits[i] == "NIST" {
ret.Prf = NIST
continue
} else if bits[i] == "RFC" {
ret.Prf = RFC
continue
} else if len(bits[i]) < 2 {
return nil, errorf("Fourth or fifth parameter is too short")
}
if bits[i][0] != 'w' {
return nil, errorf(
"Expected 'w[...]', NIST or RFC for fourth or fifth parameter")
}
w, err := strconv.Atoi(bits[i][1:])
if err != nil {
return nil, wrapErrorf(err, "Failed to parse WotsW parameter")
}
if w < 0 || w >= 1<<16 {
return nil, errorf("WotsW out of bounds")
}
ret.WotsW = uint16(w)
}
return &ret, nil
}
// List all named XMSS[MT] instances from RFC8391.
func ListNames() (names []string) {
names = make([]string, len(registry))
for i, entry := range registry {
names[i] = entry.name
}
return
}
// List names of supported and useful XMSS[MT] instances (that might not be
// named in RFC8391 and thus might not be supported by other implementations.)
func ListNames2() (names []string) {
var p Params
add := func(fh, d uint32) {
p.FullHeight = fh
p.D = d
names = append(names, p.String())
}
for _, h := range []HashFunc{SHA2, SHAKE, SHAKE256} {
for _, w := range []uint16{4, 16, 256} {
for _, n := range []uint32{16, 24, 32, 64} {
if h == SHAKE256 && (n == 64 || n == 16) {
continue
}
p.Func = h
p.WotsW = w
p.N = n
if n == 24 {
p.Prf = NIST
} else {
p.Prf = RFC
}
add(20, 2)
add(20, 4)
add(40, 2)
add(40, 4)
add(40, 8)
add(60, 3)
add(60, 6)
add(60, 12)
add(10, 1)
add(16, 1)
add(20, 1)
}
}
}
return
}
// Returns the 2log of the Winternitz parameter
func (params *Params) WotsLogW() uint8 {
switch params.WotsW {
case 4:
return 2
case 16:
return 4
case 256:
return 8
default:
panic("Only WotsW=4,16,256 are supported")
}
}
// Returns the number of main WOTS+ chains
func (params *Params) WotsLen1() uint32 {
return 8 * params.N / uint32(params.WotsLogW())
}
// Returns the number of WOTS+ checksum chains
func (params *Params) WotsLen2() uint32 {
switch params.WotsW {
case 4:
if params.N == 16 {
return 4
}
return 5
case 16:
return 3
case 256:
return 2
default:
panic("Only WotsW=4,16,256 are supported")
}
}
// Returns the total number of WOTS+ chains
func (params *Params) WotsLen() uint32 {
return params.WotsLen1() + params.WotsLen2()
}
// Returns the size of a WOTS+ signature
func (params *Params) WotsSignatureSize() uint32 {
return params.WotsLen() * params.N
}
// Returns the maximum signature sequence number
func (params *Params) MaxSignatureSeqNo() uint64 {
return (1 << params.FullHeight) - 1
}
// Returns the name and OID of this set of parameters, it is has them.
func (params *Params) LookupNameAndOid() (string, uint32) {
for _, entry := range registry {
if reflect.DeepEqual(entry.params, *params) {
return entry.name, entry.oid
}
}
return "", 0
}
// Looks up the name and oid of this set of parameters and returns whether
// any were found.
func (ctx *Context) ensureNameAndOidAreSet() bool {
if ctx.name != nil {
return true
}
var name2 string
name2, ctx.oid = ctx.p.LookupNameAndOid()
if name2 != "" {
ctx.name = &name2
return true
}
return false
}
// Returns the name of the XMSSMT instance and an empty string if it has
// no name.
func (ctx *Context) Name() string {
if ctx.ensureNameAndOidAreSet() {
return *ctx.name
}
return ""
}
// Returns the Oid of the XMSSMT instance and 0 if it has no Oid.
func (ctx *Context) Oid() uint32 {
ctx.ensureNameAndOidAreSet()
return ctx.oid
}
// Returns whether this XMSS[MT] instance is listed in the NIST Special
// Publication.
func (ctx *Context) FromNIST() bool {
ctx.ensureNameAndOidAreSet()
if ctx.mt {
return ctx.oid >= 0x21 && ctx.oid <= 0x38
}
return ctx.oid >= 0xd && ctx.oid <= 0x15
}
// Returns whether this XMSS[MT] instance is listed in the RFC (and thus should
// also be supported by other implementations).
func (ctx *Context) FromRFC() bool {
ctx.ensureNameAndOidAreSet()
if ctx.oid == 0 {
return false
}
if ctx.mt {
return ctx.oid <= 0x20
}
return ctx.oid <= 0xc
}
// Returns whether this is an XMSSMT instance (as opposed to XMSS)
func (ctx *Context) MT() bool {
return ctx.mt
}
// Get parameters of an XMSS[MT] instance
func (ctx *Context) Params() Params {
return ctx.p
}
// Returns the size of signatures of this XMSS[MT] instance
func (ctx *Context) SignatureSize() uint32 {
return ctx.sigBytes
}
var registryNameLut map[string]regEntry
var registryOidLut map[uint32]regEntry
var registryOidMTLut map[uint32]regEntry
// Initializes algorithm lookup tables.
func init() {
log = &dummyLogger{}
registryNameLut = make(map[string]regEntry)
registryOidLut = make(map[uint32]regEntry)
registryOidMTLut = make(map[uint32]regEntry)
for _, entry := range registry {
registryNameLut[entry.name] = entry
if entry.mt {
registryOidMTLut[entry.oid] = entry
} else {
registryOidLut[entry.oid] = entry
}
}
}