imported from https://bitbucket.org/ustraca/crypto
This commit is contained in:
1 parent
ca20730438
commit
8a9743f08e
11 files changed
+1805
No files matched your search
@@ -0,0 +1,28 @@
|
||||
package paillier
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
var ZERO = big.NewInt(0)
|
||||
var ONE = big.NewInt(1)
|
||||
var TWO = big.NewInt(2)
|
||||
var FOUR = big.NewInt(4)
|
||||
|
||||
// Generate a random element in the group of all the elements in Z/nZ that
|
||||
// has a multiplicative inverse.
|
||||
func GetRandomNumberInMultiplicativeGroup(n *big.Int, random io.Reader) (*big.Int, error) {
|
||||
r, err := rand.Int(random, n)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
zero := big.NewInt(0)
|
||||
one := big.NewInt(1)
|
||||
if zero.Cmp(r) == 0 || one.Cmp(new(big.Int).GCD(nil, nil, n, r)) != 0 {
|
||||
return GetRandomNumberInMultiplicativeGroup(n, random)
|
||||
}
|
||||
return r, nil
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user