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

Extend Encryption API, Improve KeyGen performance #2

Merged
merged 5 commits into from Oct 9, 2018

Conversation

cfromknecht
Copy link
Contributor

This PR extends the encryption API of this package with:

  • EncryptWithNonce - Encrypts a plaintext with user provided nonce.
  • EncryptAndNonce - Generates a random nonce, and returns it to the user along with the ciphertext.

It also makes a simple optimization to generate p and q in parallel during keygen, offering a modest speed up.

Primes generate concurrently:

goos: darwin                                                       
goarch: amd64                                                      
pkg: github.com/roasbeef/go-go-gadget-paillier                     
BenchmarkKey1024-8           100          16601491 ns/op          878931 B/op       3873 allocs/op                                     
BenchmarkKey2048-8            10         126341031 ns/op         1913843 B/op       6138 allocs/op                                     
BenchmarkKey3072-8             3         615750569 ns/op         4517426 B/op      11692 allocs/op                                     
BenchmarkKey4096-8             2        2607939290 ns/op        11143432 B/op      23340 allocs/op                                     
PASS                                                               
ok      github.com/roasbeef/go-go-gadget-paillier       12.398s 

Primes generated serially:

goos: darwin
goarch: amd64
pkg: github.com/roasbeef/go-go-gadget-paillier
BenchmarkKey1024-8            50          26715935 ns/op          972709 B/op       4209 allocs/op
BenchmarkKey2048-8            10         168290016 ns/op         1655725 B/op       5373 allocs/op
BenchmarkKey3072-8             3         803726192 ns/op         4932906 B/op      12703 allocs/op
BenchmarkKey4096-8             1        3289647242 ns/op        10710200 B/op      22465 allocs/op
PASS
ok      github.com/roasbeef/go-go-gadget-paillier       9.172s

Finally, the benchmarks have been modified to report allocations and properly reset the timer after initializing the relevant benchmarks. Several calls to Fatalf have also been corrected to use a formatting directive, allowing the package and tests to used with Go1.11. Without the directive, the compilation would fail due to the stricter vet checks at compile time.

This commit adds additional encryption features that offer
more precise control over the chosen nonces.
EncryptWithNonce will compute the CRT optimized Paillier
encryption with a provided nonce. EncryptAndNonce will
generate a random nonce for encryption, but return it to
the caller. Together, this provides more flexibility in
using the Paillier operations for other protocols that
rely on Paillier as a primitive.
Copy link
Owner

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🦎

@Roasbeef Roasbeef merged commit 14f1f86 into Roasbeef:master Oct 9, 2018
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

Successfully merging this pull request may close these issues.

None yet

2 participants