Explained how do we handle negative lambda parameter value
This commit is contained in:
2 files changed
+23
-1
No files matched your search
+7
-1
@@ -97,8 +97,14 @@ func (tk *ThresholdPublicKey) updateCprime(cprime, lambda *big.Int, share *Parti
|
|||||||
return new(big.Int).Mod(ret, tk.GetNSquare())
|
return new(big.Int).Mod(ret, tk.GetNSquare())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We use `exp` from `updateCprime` to raise decryption share to the power of lambda
|
||||||
|
// parameter. Since lambda can be a negative number and we do discrete math here,
|
||||||
|
// we need to apply multiplicative inverse modulo in this case.
|
||||||
|
//
|
||||||
|
// For instance, for b = -18:
|
||||||
|
// b^{−18} = (b^−1)^18, where b^{−1} is the multiplicative inverse modulo c.
|
||||||
func (tk *ThresholdPublicKey) exp(a, b, c *big.Int) *big.Int {
|
func (tk *ThresholdPublicKey) exp(a, b, c *big.Int) *big.Int {
|
||||||
if b.Cmp(ZERO) == -1 {
|
if b.Cmp(ZERO) == -1 { // b < 0 ?
|
||||||
ret := new(big.Int).Exp(a, new(big.Int).Neg(b), c)
|
ret := new(big.Int).Exp(a, new(big.Int).Neg(b), c)
|
||||||
return new(big.Int).ModInverse(ret, c)
|
return new(big.Int).ModInverse(ret, c)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,22 @@ func TestDelta(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExp(t *testing.T) {
|
||||||
|
tk := new(ThresholdPublicKey)
|
||||||
|
|
||||||
|
if exp := tk.exp(big.NewInt(720), big.NewInt(10), big.NewInt(49)); 43 != n(exp) {
|
||||||
|
t.Error("Unexpected exponent. Expected 43 but got", exp)
|
||||||
|
}
|
||||||
|
|
||||||
|
if exp := tk.exp(big.NewInt(720), big.NewInt(0), big.NewInt(49)); 1 != n(exp) {
|
||||||
|
t.Error("Unexpected exponent. Expected 0 but got", exp)
|
||||||
|
}
|
||||||
|
|
||||||
|
if exp := tk.exp(big.NewInt(720), big.NewInt(-10), big.NewInt(49)); 8 != n(exp) {
|
||||||
|
t.Error("Unexpected exponent. Expected 8 but got", exp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCombineSharesConstant(t *testing.T) {
|
func TestCombineSharesConstant(t *testing.T) {
|
||||||
tk := new(ThresholdPublicKey)
|
tk := new(ThresholdPublicKey)
|
||||||
tk.N = big.NewInt(101 * 103)
|
tk.N = big.NewInt(101 * 103)
|
||||||
|
|||||||
Reference in new issue
Block a user