Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: invalid memory address or nil pointer dereference #13

Open
eozturk1 opened this issue Mar 30, 2021 · 1 comment
Open

Comments

@eozturk1
Copy link

I have been trying to use the library but I get the error in the title. Here is the code I am using:

p, q, err := paillier.GenerateSafePrime(
	1024,
	4,
	10000000000,
	rand.Reader,
)
if err != nil {
	panic("DidierCrunchPaillier GenerateSafePrime error: " + err.Error())
}
privateKey := paillier.CreatePrivateKey(p, q)
toEncrypt := big.NewInt(19)
cipher, err := privateKey.Encrypt(toEncrypt, rand.Reader)
if err != nil {
	panic("DidierCrunchPaillier Encrypt error: " + err.Error())
}
plain := privateKey.Decrypt(cipher)
fmt.Println("Plaintext: " + plain.String())

The issue is with the decryption function. Here is the trace:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x1033a3c]

goroutine 1 [running]:
math/big.(*Int).Mul(0xc00005fde8, 0xc00006c7c0, 0x0, 0x0)
	  C:/Program Files/Go/src/math/big/int.go:168 +0x1dc
github.com/didiercrunch/paillier.(*PrivateKey).Decrypt(0xc000104300, 0xc000148028, 0x0)
	C:/Users/eoztu/go/pkg/mod/github.com/didiercrunch/[email protected]/paillier.go:121 +0x1f9
...

When I use small primes as in tests (e.g., 13, 17), enc/dec both works but not with generated primes. Am I using the API wrong?

@brandonbryant12
Copy link

same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants