Browse Source

Update the chacha20 import path, minor cleanups

Yawning Angel 3 months ago
parent
commit
2b21e6fe6b
5 changed files with 36 additions and 11 deletions
  1. 2 2
      benchmark_test.go
  2. 2 2
      error_correction.go
  3. 8 0
      go.mod
  4. 17 0
      go.sum
  5. 7 7
      poly.go

+ 2 - 2
benchmark_test.go

@@ -15,7 +15,7 @@ import (
 
 func benchGenerateKeyPairAlice(b *testing.B) {
 	for i := 0; i < b.N; i++ {
-		GenerateKeyPairAlice(rand.Reader)
+		_, _, _ = GenerateKeyPairAlice(rand.Reader)
 	}
 }
 
@@ -98,7 +98,7 @@ func BenchmarkNewHopeTor(b *testing.B) {
 
 func benchGenerateKeyPairSimpleAlice(b *testing.B) {
 	for i := 0; i < b.N; i++ {
-		GenerateKeyPairSimpleAlice(rand.Reader)
+		_, _, _ = GenerateKeyPairSimpleAlice(rand.Reader)
 	}
 }
 

+ 2 - 2
error_correction.go

@@ -7,7 +7,7 @@
 
 package newhope
 
-import "git.schwanenlied.me/yawning/chacha20.git"
+import "gitlab.com/yawning/chacha20.git"
 
 func abs(v int32) int32 {
 	mask := v >> 31
@@ -73,7 +73,7 @@ func (c *poly) helpRec(v *poly, seed *[SeedBytes]byte, nonce byte) {
 
 	n[7] = nonce
 
-	stream, err := chacha20.NewCipher(seed[:], n[:])
+	stream, err := chacha20.New(seed[:], n[:])
 	if err != nil {
 		panic(err)
 	}

+ 8 - 0
go.mod

@@ -0,0 +1,8 @@
+module gitlab.com/yawning/newhope.git
+
+go 1.12
+
+require (
+	gitlab.com/yawning/chacha20.git v0.0.0-20190902183103-644b09ac4e6e
+	golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
+)

+ 17 - 0
go.sum

@@ -0,0 +1,17 @@
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+gitlab.com/yawning/chacha20.git v0.0.0-20190902183103-644b09ac4e6e h1:QhupcTDYYRrhIY0f5Ad5v/nU8lJWjzzN6qQu1ndOm0c=
+gitlab.com/yawning/chacha20.git v0.0.0-20190902183103-644b09ac4e6e/go.mod h1:3x6b94nWCP/a2XB/joOPMiGYUBvqbLfeY/BkHLeDs6s=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM=
+golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190902133755-9109b7679e13 h1:tdsQdquKbTNMsSZLqnLELJGzCANp9oXhu6zFBW6ODx4=
+golang.org/x/sys v0.0.0-20190902133755-9109b7679e13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

+ 7 - 7
poly.go

@@ -10,7 +10,7 @@ package newhope
 import (
 	"encoding/binary"
 
-	"git.schwanenlied.me/yawning/chacha20.git"
+	"gitlab.com/yawning/chacha20.git"
 	"golang.org/x/crypto/sha3"
 )
 
@@ -115,8 +115,8 @@ func (p *poly) uniform(seed *[SeedBytes]byte, torSampling bool) {
 
 		// h and buf are left unscrubbed because the output is public.
 		h := sha3.NewShake128()
-		h.Write(seed[:])
-		h.Read(buf[:])
+		_, _ = h.Write(seed[:])
+		_, _ = h.Read(buf[:])
 
 		for ctr, pos := 0, 0; ctr < paramN; {
 			val := binary.LittleEndian.Uint16(buf[pos:])
@@ -128,7 +128,7 @@ func (p *poly) uniform(seed *[SeedBytes]byte, torSampling bool) {
 			pos += 2
 			if pos > shake128Rate*nBlocks-2 {
 				nBlocks = 1
-				h.Read(buf[:shake128Rate])
+				_, _ = h.Read(buf[:shake128Rate])
 				pos = 0
 			}
 		}
@@ -140,10 +140,10 @@ func (p *poly) uniform(seed *[SeedBytes]byte, torSampling bool) {
 
 		// h and buf are left unscrubbed because the output is public.
 		h := sha3.NewShake128()
-		h.Write(seed[:])
+		_, _ = h.Write(seed[:])
 
 		for {
-			h.Read(buf[:])
+			_, _ = h.Read(buf[:])
 			if !p.discardTo(buf[:]) {
 				break
 			}
@@ -159,7 +159,7 @@ func (p *poly) getNoise(seed *[SeedBytes]byte, nonce byte) {
 	var n [8]byte
 
 	n[0] = nonce
-	stream, err := chacha20.NewCipher(seed[:], n[:])
+	stream, err := chacha20.New(seed[:], n[:])
 	if err != nil {
 		panic(err)
 	}