Skip to content

Commit

Permalink
Further optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
nadimkobeissi committed Jul 31, 2020
1 parent 4ce4d11 commit 641535d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion indcpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 6 additions & 11 deletions poly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

0 comments on commit 641535d

Please sign in to comment.