From 641535dd4e5c7bdfaea281e65faefe896a018050 Mon Sep 17 00:00:00 2001 From: Nadim Kobeissi Date: Fri, 31 Jul 2020 13:16:19 +0200 Subject: [PATCH] Further optimizations --- README.md | 20 ++++++++++---------- indcpa.go | 3 ++- poly.go | 17 ++++++----------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 0ed6d37..921f58d 100644 --- a/README.md +++ b/README.md @@ -69,17 +69,17 @@ ok github.com/symbolicsoft/kyber-k2so 1.140s goos: linux goarch: amd64 pkg: github.com/symbolicsoft/kyber-k2so -BenchmarkKemKeypair512-8 28089 45174 ns/op -BenchmarkKemKeypair768-8 15427 69505 ns/op -BenchmarkKemKeypair1024-8 10000 126179 ns/op -BenchmarkKemEncrypt512-8 20823 55941 ns/op -BenchmarkKemEncrypt768-8 14752 87413 ns/op -BenchmarkKemEncrypt1024-8 9400 127322 ns/op -BenchmarkKemDecrypt512-8 17260 71100 ns/op -BenchmarkKemDecrypt768-8 10000 100249 ns/op -BenchmarkKemDecrypt1024-8 8785 144723 ns/op +BenchmarkKemKeypair512-8 28116 41519 ns/op +BenchmarkKemKeypair768-8 15864 74150 ns/op +BenchmarkKemKeypair1024-8 10000 105946 ns/op +BenchmarkKemEncrypt512-8 21409 56336 ns/op +BenchmarkKemEncrypt768-8 13629 87541 ns/op +BenchmarkKemEncrypt1024-8 9987 131054 ns/op +BenchmarkKemDecrypt512-8 17650 65348 ns/op +BenchmarkKemDecrypt768-8 12352 99300 ns/op +BenchmarkKemDecrypt1024-8 8913 140804 ns/op PASS -ok github.com/symbolicsoft/kyber-k2so 15.215s +ok github.com/symbolicsoft/kyber-k2so 16.180s ``` # About Kyber-K2SO diff --git a/indcpa.go b/indcpa.go index 2833a6b..5f173e9 100644 --- a/indcpa.go +++ b/indcpa.go @@ -185,7 +185,8 @@ func indcpaEncrypt(m []byte, publicKey []byte, coins []byte, paramsK int) ([]byt v = polyInvNttToMont(v) polyvecAdd(bp, ep, paramsK) v = polyAdd(polyAdd(v, epp), k) - return indcpaPackCiphertext(polyvecReduce(bp, paramsK), polyReduce(v), paramsK), nil + polyvecReduce(bp, paramsK) + return indcpaPackCiphertext(bp, polyReduce(v), paramsK), nil } func indcpaDecrypt(c []byte, privateKey []byte, paramsK int) []byte { diff --git a/poly.go b/poly.go index c292292..9006bfd 100644 --- a/poly.go +++ b/poly.go @@ -225,7 +225,7 @@ func polySub(a poly, b poly) poly { func polyvecCompress(a polyvec, paramsK int) []byte { var r []byte - a = polyvecCSubQ(a, paramsK) + polyvecCSubQ(a, paramsK) rr := 0 switch paramsK { case 2: @@ -335,18 +335,16 @@ func polyvecFromBytes(a []byte, paramsK int) polyvec { return r } -func polyvecNtt(r polyvec, paramsK int) polyvec { +func polyvecNtt(r polyvec, paramsK int) { for i := 0; i < paramsK; i++ { r[i] = polyNtt(r[i]) } - return r } -func polyvecInvNttToMont(r polyvec, paramsK int) polyvec { +func polyvecInvNttToMont(r polyvec, paramsK int) { for i := 0; i < paramsK; i++ { r[i] = polyInvNttToMont(r[i]) } - return r } func polyvecPointWiseAccMontgomery(a polyvec, b polyvec, paramsK int) poly { @@ -358,23 +356,20 @@ func polyvecPointWiseAccMontgomery(a polyvec, b polyvec, paramsK int) poly { return polyReduce(r) } -func polyvecReduce(r polyvec, paramsK int) polyvec { +func polyvecReduce(r polyvec, paramsK int) { for i := 0; i < paramsK; i++ { r[i] = polyReduce(r[i]) } - return r } -func polyvecCSubQ(r polyvec, paramsK int) polyvec { +func polyvecCSubQ(r polyvec, paramsK int) { for i := 0; i < paramsK; i++ { r[i] = polyCSubQ(r[i]) } - return r } -func polyvecAdd(a polyvec, b polyvec, paramsK int) polyvec { +func polyvecAdd(a polyvec, b polyvec, paramsK int) { for i := 0; i < paramsK; i++ { a[i] = polyAdd(a[i], b[i]) } - return a }