-
Notifications
You must be signed in to change notification settings - Fork 0
/
plus_minus.go
54 lines (44 loc) · 1.75 KB
/
plus_minus.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
package sample
import (
"io"
"github.com/cronokirby/saferith"
"github.com/w3-key/mps-lean/pkg/math/curve"
"github.com/w3-key/mps-lean/pkg/params"
)
func sampleNeg(rand io.Reader, bits int) *saferith.Int {
buf := make([]byte, bits/8+1)
mustReadBits(rand, buf)
neg := saferith.Choice(buf[0] & 1)
buf = buf[1:]
out := new(saferith.Int).SetBytes(buf)
out.Neg(neg)
return out
}
// IntervalL returns an integer in the range ± 2ˡ, but with constant-time properties.
func IntervalL(rand io.Reader) *saferith.Int {
return sampleNeg(rand, params.L)
}
// IntervalLPrime returns an integer in the range ± 2ˡ', but with constant-time properties.
func IntervalLPrime(rand io.Reader) *saferith.Int {
return sampleNeg(rand, params.LPrime)
}
// IntervalLEps returns an integer in the range ± 2ˡ⁺ᵉ, but with constant-time properties.
func IntervalLEps(rand io.Reader) *saferith.Int {
return sampleNeg(rand, params.LPlusEpsilon)
}
// IntervalLPrimeEps returns an integer in the range ± 2ˡ'⁺ᵉ, but with constant-time properties.
func IntervalLPrimeEps(rand io.Reader) *saferith.Int {
return sampleNeg(rand, params.LPrimePlusEpsilon)
}
// IntervalLN returns an integer in the range ± 2ˡ•N, where N is the size of a Paillier modulus.
func IntervalLN(rand io.Reader) *saferith.Int {
return sampleNeg(rand, params.L+params.BitsIntModN)
}
// IntervalLEpsN returns an integer in the range ± 2ˡ⁺ᵉ•N, where N is the size of a Paillier modulus.
func IntervalLEpsN(rand io.Reader) *saferith.Int {
return sampleNeg(rand, params.LPlusEpsilon+params.BitsIntModN)
}
// IntervalScalar returns an integer in the range ±q, with q the size of a Scalar.
func IntervalScalar(rand io.Reader, group curve.Curve) *saferith.Int {
return sampleNeg(rand, group.ScalarBits())
}