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

Open
opened 2021-03-30 13:31:00 -04:00 by eozturk1 · 1 comment
eozturk1 commented 2021-03-30 13:31:00 -04:00 (Migrated from github.com)

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/paillier@v0.0.0-20180810105046-753322e473bf/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?

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/paillier@v0.0.0-20180810105046-753322e473bf/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 commented 2024-08-09 16:02:50 -04:00 (Migrated from github.com)

same issue

same issue
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: didier/paillier#13