Skip to content
Snippets Groups Projects
Commit c19036f4 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Remove all remaining instances of Sum that are not Sum(nil) per new guidelines...

Remove all remaining instances of Sum that are not Sum(nil) per new guidelines to only permit this pattern in the codebase
parent a41b0b45
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,9 @@ import (
"bytes"
cryptoCipher "crypto/cipher"
"encoding/base64"
"io"
"strings"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/crypto/backup"
......@@ -19,8 +22,6 @@ import (
"golang.org/x/crypto/argon2"
"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/chacha20poly1305"
"io"
"strings"
)
// Error messages.
......@@ -376,10 +377,16 @@ func decryptPrivateKey(data, key []byte) ([]byte, error) {
// initChaCha20Poly1305Pk returns a XChaCha20-Poly1305 cipher.AEAD that uses the
// given password hashed into a 256-bit key.
func initChaCha20Poly1305Pk(key []byte) cryptoCipher.AEAD {
pwHash := blake2b.Sum256(key)
blake, err := blake2b.New256(nil)
if err != nil {
jww.FATAL.Panicf("could not init blake2b: %+v", err)
}
blake.Write(key)
pwHash := blake.Sum(nil)
chaCipher, err := chacha20poly1305.NewX(pwHash[:])
if err != nil {
jww.FATAL.Panicf("Could not init XChaCha20Poly1305 mode: %+v", err)
jww.FATAL.Panicf("could not init XChaCha20Poly1305 mode: %+v",
err)
}
return chaCipher
......
......@@ -12,16 +12,17 @@ import (
"crypto/cipher"
"encoding/base64"
"encoding/binary"
"github.com/pkg/errors"
"github.com/sethvargo/go-diceware/diceware"
jww "github.com/spf13/jwalterweatherman"
"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/chacha20poly1305"
"io"
goUrl "net/url"
"strconv"
"strings"
"time"
"github.com/pkg/errors"
"github.com/sethvargo/go-diceware/diceware"
jww "github.com/spf13/jwalterweatherman"
"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/chacha20poly1305"
)
// The current version number of the share URL structure.
......@@ -171,7 +172,13 @@ func HashURLPassword(password string) []byte {
return []byte{}
}
pwHash := blake2b.Sum256([]byte(password))
blake, err := blake2b.New256(nil)
if err != nil {
jww.ERROR.Printf("could not init blake2b: %+v", err)
}
blake.Write([]byte(password))
pwHash := blake.Sum(nil)
return pwHash[:]
}
......@@ -688,7 +695,12 @@ func decryptShareURL(data, password []byte) ([]byte, error) {
// initChaCha20Poly1305 returns a XChaCha20-Poly1305 cipher.AEAD that uses the
// given password hashed into a 256-bit key.
func initChaCha20Poly1305(password []byte) cipher.AEAD {
pwHash := blake2b.Sum256(password)
blake, err := blake2b.New256(nil)
if err != nil {
jww.FATAL.Panicf("could not init blake2b: %+v", err)
}
blake.Write(password)
pwHash := blake.Sum(nil)
chaCipher, err := chacha20poly1305.NewX(pwHash[:])
if err != nil {
jww.FATAL.Panicf("Could not init XChaCha20Poly1305 mode: %+v", err)
......
......@@ -9,13 +9,14 @@ package channel
import (
cryptoCipher "crypto/cipher"
"io"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/crypto/backup"
"golang.org/x/crypto/argon2"
"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/chacha20poly1305"
"io"
)
// Error messages.
......@@ -61,10 +62,16 @@ func decryptIdentity(data, key []byte) ([]byte, error) {
// initChaCha20Poly1305 returns a XChaCha20-Poly1305 cipher.AEAD that uses the
// given password hashed into a 256-bit key.
func initChaCha20Poly1305(key []byte) cryptoCipher.AEAD {
pwHash := blake2b.Sum256(key)
blake, err := blake2b.New256(nil)
if err != nil {
jww.FATAL.Panicf("could not init blake2b: %+v", err)
}
blake.Write(key)
pwHash := blake.Sum(nil)
chaCipher, err := chacha20poly1305.NewX(pwHash[:])
if err != nil {
jww.FATAL.Panicf("Could not init XChaCha20Poly1305 mode: %+v", err)
jww.FATAL.Panicf("could not init XChaCha20Poly1305 mode: %+v",
err)
}
return chaCipher
......
......@@ -62,10 +62,16 @@ func decryptIdentity(data, key []byte) ([]byte, error) {
// initChaCha20Poly1305 returns a XChaCha20-Poly1305 cipher.AEAD that uses the
// given password hashed into a 256-bit key.
func initChaCha20Poly1305(key []byte) cryptoCipher.AEAD {
pwHash := blake2b.Sum256(key)
blake, err := blake2b.New256(nil)
if err != nil {
jww.FATAL.Panicf("could not init blake2b: %+v", err)
}
blake.Write(key)
pwHash := blake.Sum(nil)
chaCipher, err := chacha20poly1305.NewX(pwHash[:])
if err != nil {
jww.FATAL.Panicf("Could not init XChaCha20Poly1305 mode: %+v", err)
jww.FATAL.Panicf("could not init XChaCha20Poly1305 mode: %+v",
err)
}
return chaCipher
......
......@@ -11,13 +11,14 @@ import (
cryptoCipher "crypto/cipher"
"encoding/binary"
"encoding/json"
"io"
"github.com/Max-Sum/base32768"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/crypto/hash"
"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/chacha20poly1305"
"io"
)
// Error messages.
......@@ -271,10 +272,16 @@ func deriveDatabaseSecret(password, salt []byte) []byte {
// initChaCha20Poly1305 returns a XChaCha20-Poly1305 cipher.AEAD that uses the
// given password hashed into a 256-bit key.
func initChaCha20Poly1305(key []byte) cryptoCipher.AEAD {
pwHash := blake2b.Sum256(key)
blake, err := blake2b.New256(nil)
if err != nil {
jww.FATAL.Panicf("could not initialize blake2b: %+v", err)
}
blake.Write(key)
pwHash := blake.Sum(nil)
chaCipher, err := chacha20poly1305.NewX(pwHash[:])
if err != nil {
jww.FATAL.Panicf("Could not init XChaCha20Poly1305 mode: %+v", err)
jww.FATAL.Panicf("could not init XChaCha20Poly1305 mode: %+v",
err)
}
return chaCipher
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment