Commit 641535dd authored by Nadim Kobeissi's avatar Nadim Kobeissi 💎

Further optimizations

parent 4ce4d114
......@@ -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
......
......@@ -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 {
......
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment