-
Notifications
You must be signed in to change notification settings - Fork 2
/
sysparams.go
111 lines (100 loc) · 2.97 KB
/
sysparams.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
// Copyright 2016 Maarten Everts. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gabi
import (
"sort"
)
// BaseParameters holds the base system parameters
type BaseParameters struct {
Le uint
LePrime uint
Lh uint
Lm uint
Ln uint
Lstatzk uint
Lv uint
}
// defaultBaseParameters holds per keylength the base parameters.
var defaultBaseParameters = map[int]BaseParameters{
1024: BaseParameters{
Le: 597,
LePrime: 120,
Lh: 256,
Lm: 256,
Ln: 1024,
Lstatzk: 80,
Lv: 1700,
},
2048: BaseParameters{
Le: 645,
LePrime: 120,
Lh: 256,
Lm: 256,
Ln: 2048,
Lstatzk: 128,
Lv: 1700,
},
4096: BaseParameters{
Le: 901,
LePrime: 120,
Lh: 256,
Lm: 512,
Ln: 4096,
Lstatzk: 128,
Lv: 1700,
},
}
// DerivedParameters holds system parameters that can be drived from base
// systemparameters (BaseParameters)
type DerivedParameters struct {
LeCommit uint
LmCommit uint
LRA uint
LsCommit uint
LvCommit uint
LvPrime uint
LvPrimeCommit uint
}
// MakeDerivedParameters computes the derived system parameters
func MakeDerivedParameters(base BaseParameters) DerivedParameters {
return DerivedParameters{
LeCommit: base.LePrime + base.Lstatzk + base.Lh,
LmCommit: base.Lm + base.Lstatzk + base.Lh,
LRA: base.Ln + base.Lstatzk,
LsCommit: base.Lm + base.Lstatzk + base.Lh + 1,
LvCommit: base.Lv + base.Lstatzk + base.Lh,
LvPrime: base.Ln + base.Lstatzk,
LvPrimeCommit: base.Ln + 2*base.Lstatzk + base.Lh,
}
}
// SystemParameters holds the system parameters of the IRMA system.
type SystemParameters struct {
BaseParameters
DerivedParameters
}
// DefaultSystemParameters holds per keylength the default parameters as are
// currently in use at the moment. This might (and probably will) change in the
// future.
var DefaultSystemParameters = map[int]*SystemParameters{
1024: &SystemParameters{defaultBaseParameters[1024], MakeDerivedParameters(defaultBaseParameters[1024])},
2048: &SystemParameters{defaultBaseParameters[2048], MakeDerivedParameters(defaultBaseParameters[2048])},
4096: &SystemParameters{defaultBaseParameters[4096], MakeDerivedParameters(defaultBaseParameters[4096])},
}
// getAvailableKeyLengths returns the keylengths for the provided map of system
// parameters.
func getAvailableKeyLengths(sysParamsMap map[int]*SystemParameters) []int {
lengths := make([]int, 0, len(sysParamsMap))
for k := range sysParamsMap {
lengths = append(lengths, k)
}
sort.Ints(lengths)
return lengths
}
// DefaultKeyLengths is a slice of integers holding the keylengths for which
// system parameters are available.
var DefaultKeyLengths = getAvailableKeyLengths(DefaultSystemParameters)
// ParamSize computes the size of a parameter in bytes given the size in bits.
func ParamSize(a int) int {
return (a + 8 - 1) / 8
}