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

Random production of corrupt ciphertext #86

Closed
gmaiainc opened this issue Dec 14, 2023 · 0 comments
Closed

Random production of corrupt ciphertext #86

gmaiainc opened this issue Dec 14, 2023 · 0 comments

Comments

@gmaiainc
Copy link
Contributor

The package appears to have a bug where it will randomly produce a ciphertext it cannot decipher. This is easily reproducible with the following Go program, largely based on the example in the Readme:

package main

import (
	"log"

	ecies "github.com/ecies/go/v2"
)

func main() {
	k, err := ecies.GenerateKey()
	if err != nil {
		panic(err)
	}
	log.Println("key pair has been generated")

	for {
		ciphertext, err := ecies.Encrypt(k.PublicKey, []byte("THIS IS THE TEST"))
		if err != nil {
			panic(err)
		}

		_, err = ecies.Decrypt(k, ciphertext)
		if err != nil {
			panic(err)
		}
	}
}

The expectation is that this program loops forever, however, what actually happens is that after a certain number of iterations (usually in the order of a few thousand), Decrypt will fail with an error: "invalid public key". This is because the Encrypt function is rarely producing a ciphertext that does not appear to be valid.

gmaiainc added a commit to gmaiainc/ecies-go that referenced this issue Dec 14, 2023
gmaiainc added a commit to gmaiainc/ecies-go that referenced this issue Dec 14, 2023
savely-krasovsky pushed a commit that referenced this issue Dec 14, 2023
* fix: bug in zeroPad implementation

* fix: replaced broken, duplicate zeroPad code

* test: added benchmark that would make #86 more obvious
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