-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
102 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright © 2019 Binance, threshold-network | ||
// | ||
// This file is part of Binance. The full Binance copyright notice, including | ||
// terms governing use, modification, and redistribution, is contained in the | ||
// file LICENSE at the root of the source code distribution tree. | ||
// | ||
// derived from https://github.com/threshold-network/tss-lib/blob/2e712689cfbeefede15f95a0ec7112227d86f702/crypto/paillier/paillier.go#L296 | ||
|
||
package main | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/bnb-chain/tss-lib/v2/ecdsa/keygen" | ||
) | ||
|
||
func isPreParamsUpgradable(preParams *keygen.LocalPreParams) bool { | ||
return preParams.PaillierSK.P == nil | ||
} | ||
|
||
// upgradePreParams derives the missing PaillierSK parameters from the existing ones | ||
func upgradePreParams(preParams *keygen.LocalPreParams) { | ||
n := preParams.PaillierSK.PublicKey.N | ||
phiN := preParams.PaillierSK.PhiN | ||
|
||
m := new(big.Int).Sub(n, phiN) // pq - (p-1)(q-1) = p + q - 1 | ||
m.Add(m, big.NewInt(1)) // (p + q - 1) + 1 = p + q | ||
m.Div(m, big.NewInt(2)) // (p + q) / 2 | ||
|
||
m2 := new(big.Int).Mul(m, m) // (p + q)^2 / 4 | ||
// = (pp + qq + 2pq) / 4 | ||
m2subN := new(big.Int).Sub(m2, n) // ((p + q)^2 / 4) - n = ((p + q)^2 / 4) - pq | ||
// = (pp + qq + 2pq) / 4 - pq | ||
// = (pp + qq + 2pq - 4pq) / 4 | ||
// = (pp - 2pq + qq) / 4 | ||
// = (p - q)^2 / 4 | ||
s := new(big.Int).Sqrt(m2subN) // = sqrt((p - q)^2 / 4) | ||
// = |p - q| / 2 | ||
|
||
p := new(big.Int).Add(m, s) // (p + q) / 2 + |p - q| / 2, assuming p >= q | ||
q := new(big.Int).Sub(m, s) // (p + q) / 2 - |p - q| / 2, assuming p >= q | ||
|
||
preParams.PaillierSK.P = p | ||
preParams.PaillierSK.Q = q | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.