Skip to content
Snippets Groups Projects
Commit 9db4026c authored by Jono Wenger's avatar Jono Wenger
Browse files

Replace usages of MD5 with blake2b

parent 707141eb
No related branches found
No related tags found
1 merge request!23Release
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
package partition package partition
import ( import (
"crypto/md5"
"encoding/binary" "encoding/binary"
"gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"golang.org/x/crypto/blake2b"
"sync" "sync"
"time" "time"
) )
...@@ -69,7 +69,15 @@ func (s *Store) load(partner *id.ID, messageID uint64) *multiPartMessage { ...@@ -69,7 +69,15 @@ func (s *Store) load(partner *id.ID, messageID uint64) *multiPartMessage {
} }
func getMultiPartID(partner *id.ID, messageID uint64) multiPartID { func getMultiPartID(partner *id.ID, messageID uint64) multiPartID {
h, _ := blake2b.New256(nil)
h.Write(partner.Bytes())
b := make([]byte, 8) b := make([]byte, 8)
binary.BigEndian.PutUint64(b, messageID) binary.BigEndian.PutUint64(b, messageID)
return md5.Sum(append(partner[:], b...)) h.Write(b)
var mpID multiPartID
copy(mpID[:], h.Sum(nil))
return mpID
} }
...@@ -2,7 +2,6 @@ package reception ...@@ -2,7 +2,6 @@ package reception
import ( import (
"bytes" "bytes"
"crypto/md5"
"encoding/json" "encoding/json"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
...@@ -11,6 +10,7 @@ import ( ...@@ -11,6 +10,7 @@ import (
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"golang.org/x/crypto/blake2b"
"io" "io"
"strconv" "strconv"
"sync" "sync"
...@@ -46,12 +46,11 @@ type storedReference struct { ...@@ -46,12 +46,11 @@ type storedReference struct {
type idHash [16]byte type idHash [16]byte
func makeIdHash(ephID ephemeral.Id, source *id.ID) idHash { func makeIdHash(ephID ephemeral.Id, source *id.ID) idHash {
h := md5.New() h, _ := blake2b.New256(nil)
h.Write(ephID[:]) h.Write(ephID[:])
h.Write(source.Bytes()) h.Write(source.Bytes())
idHashBytes := h.Sum(nil)
idH := idHash{} idH := idHash{}
copy(idH[:], idHashBytes) copy(idH[:], h.Sum(nil))
return idH return idH
} }
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
package utility package utility
import ( import (
"crypto/md5"
"encoding/json" "encoding/json"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
...@@ -16,6 +15,7 @@ import ( ...@@ -16,6 +15,7 @@ import (
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"golang.org/x/crypto/blake2b"
) )
const currentCmixMessageVersion = 0 const currentCmixMessageVersion = 0
...@@ -80,8 +80,14 @@ func (cmh *cmixMessageHandler) DeleteMessage(kv *versioned.KV, key string) error ...@@ -80,8 +80,14 @@ func (cmh *cmixMessageHandler) DeleteMessage(kv *versioned.KV, key string) error
// HashMessage generates a hash of the message. // HashMessage generates a hash of the message.
func (cmh *cmixMessageHandler) HashMessage(m interface{}) MessageHash { func (cmh *cmixMessageHandler) HashMessage(m interface{}) MessageHash {
sm := m.(storedMessage) h, _ := blake2b.New256(nil)
return md5.Sum(sm.Marshal())
h.Write(m.(storedMessage).Marshal())
var messageHash MessageHash
copy(messageHash[:], h.Sum(nil))
return messageHash
} }
// CmixMessageBuffer wraps the message buffer to store and load raw cmix // CmixMessageBuffer wraps the message buffer to store and load raw cmix
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
package utility package utility
import ( import (
"crypto/md5"
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
...@@ -17,6 +16,7 @@ import ( ...@@ -17,6 +16,7 @@ import (
"gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"golang.org/x/crypto/blake2b"
) )
const currentE2EMessageVersion = 0 const currentE2EMessageVersion = 0
...@@ -80,17 +80,19 @@ func (emh *e2eMessageHandler) DeleteMessage(kv *versioned.KV, key string) error ...@@ -80,17 +80,19 @@ func (emh *e2eMessageHandler) DeleteMessage(kv *versioned.KV, key string) error
// Do not include the params in the hash so it is not needed to resubmit the // Do not include the params in the hash so it is not needed to resubmit the
// message into succeeded or failed // message into succeeded or failed
func (emh *e2eMessageHandler) HashMessage(m interface{}) MessageHash { func (emh *e2eMessageHandler) HashMessage(m interface{}) MessageHash {
msg := m.(e2eMessage) h, _ := blake2b.New256(nil)
var digest []byte
digest = append(digest, msg.Recipient...)
digest = append(digest, msg.Payload...)
msg := m.(e2eMessage)
h.Write(msg.Recipient)
h.Write(msg.Payload)
mtBytes := make([]byte, 4) mtBytes := make([]byte, 4)
binary.BigEndian.PutUint32(mtBytes, msg.MessageType) binary.BigEndian.PutUint32(mtBytes, msg.MessageType)
digest = append(digest, mtBytes...) h.Write(mtBytes)
var messageHash MessageHash
copy(messageHash[:], h.Sum(nil))
return md5.Sum(digest) return messageHash
} }
// E2eMessageBuffer wraps the message buffer to store and load raw e2eMessages. // E2eMessageBuffer wraps the message buffer to store and load raw e2eMessages.
......
...@@ -9,11 +9,11 @@ package utility ...@@ -9,11 +9,11 @@ package utility
import ( import (
"bytes" "bytes"
"crypto/md5"
"encoding/json" "encoding/json"
"gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/ekv" "gitlab.com/elixxir/ekv"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"golang.org/x/crypto/blake2b"
"math/rand" "math/rand"
"os" "os"
"reflect" "reflect"
...@@ -48,10 +48,14 @@ func (th *testHandler) DeleteMessage(kv *versioned.KV, key string) error { ...@@ -48,10 +48,14 @@ func (th *testHandler) DeleteMessage(kv *versioned.KV, key string) error {
} }
func (th *testHandler) HashMessage(m interface{}) MessageHash { func (th *testHandler) HashMessage(m interface{}) MessageHash {
mBytes := m.([]byte) h, _ := blake2b.New256(nil)
// Sum returns a array that is the exact same size as the MessageHash and Go
// apparently automatically casts it h.Write(m.([]byte))
return md5.Sum(mBytes)
var messageHash MessageHash
copy(messageHash[:], h.Sum(nil))
return messageHash
} }
func newTestHandler() *testHandler { func newTestHandler() *testHandler {
...@@ -343,7 +347,13 @@ func makeTestMessages(n int) ([][]byte, map[MessageHash]struct{}) { ...@@ -343,7 +347,13 @@ func makeTestMessages(n int) ([][]byte, map[MessageHash]struct{}) {
for i := range msgs { for i := range msgs {
msgs[i] = make([]byte, 256) msgs[i] = make([]byte, 256)
prng.Read(msgs[i]) prng.Read(msgs[i])
mh[md5.Sum(msgs[i])] = struct{}{}
h, _ := blake2b.New256(nil)
h.Write(msgs[i])
var messageHash MessageHash
copy(messageHash[:], h.Sum(nil))
mh[messageHash] = struct{}{}
} }
return msgs, mh return msgs, mh
......
...@@ -8,13 +8,13 @@ ...@@ -8,13 +8,13 @@
package utility package utility
import ( import (
"crypto/md5"
"encoding/json" "encoding/json"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/format"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
"golang.org/x/crypto/blake2b"
"time" "time"
) )
...@@ -77,9 +77,14 @@ func (*meteredCmixMessageHandler) DeleteMessage(kv *versioned.KV, key string) er ...@@ -77,9 +77,14 @@ func (*meteredCmixMessageHandler) DeleteMessage(kv *versioned.KV, key string) er
// HashMessage generates a hash of the message. // HashMessage generates a hash of the message.
func (*meteredCmixMessageHandler) HashMessage(m interface{}) MessageHash { func (*meteredCmixMessageHandler) HashMessage(m interface{}) MessageHash {
msg := m.(meteredCmixMessage) h, _ := blake2b.New256(nil)
h.Write(m.(meteredCmixMessage).M)
var messageHash MessageHash
copy(messageHash[:], h.Sum(nil))
return md5.Sum(msg.M) return messageHash
} }
// CmixMessageBuffer wraps the message buffer to store and load raw cmix // CmixMessageBuffer wraps the message buffer to store and load raw cmix
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment