Skip to content

Commit

Permalink
Remove diode_go_client/crypto/sha3
Browse files Browse the repository at this point in the history
After add -race flag when test, got this error in old sha3 library:
x/crypto: fatal error: checkptr: unsafe pointer conversion (golang/go#37644)
Since they have already fixed the issue, it's better to switch to official crypto library.
  • Loading branch information
sc0Vu committed Jun 28, 2020
1 parent e02dd40 commit 5a243f1
Show file tree
Hide file tree
Showing 20 changed files with 12 additions and 1,695 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ all: $(BINS)

.PHONY: test
test:
go test $(TESTS)
go test -race $(TESTS)

.PHONY: lint
lint:
Expand Down
11 changes: 3 additions & 8 deletions contract/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

"github.com/diodechain/diode_go_client/accounts/abi"
"github.com/diodechain/diode_go_client/crypto/sha3"
"github.com/diodechain/diode_go_client/crypto"
"github.com/diodechain/diode_go_client/util"
)

Expand Down Expand Up @@ -50,14 +50,9 @@ func (dnsContract *DNSContract) Register(_name string, _record Address) (data []

// DNSMetaKey returns storage key of Meta entry (destination, owner, name)
func DNSMetaKey(name string) []byte {
hash := sha3.NewKeccak256()
hash.Write([]byte(name))
key := hash.Sum(nil)

key := crypto.Sha3Hash([]byte(name))
index := util.IntToBytes(DNSNamesIndex)
padIndex := util.PaddingBytesPrefix(index, 0, 32)
padKey := util.PaddingBytesPrefix(key, 0, 32)
hash = sha3.NewKeccak256()
hash.Write(append(padKey, padIndex...))
return hash.Sum(nil)
return crypto.Sha3Hash(append(padKey, padIndex...))
}
14 changes: 4 additions & 10 deletions contract/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

"github.com/diodechain/diode_go_client/accounts/abi"
"github.com/diodechain/diode_go_client/crypto/sha3"
"github.com/diodechain/diode_go_client/crypto"
"github.com/diodechain/diode_go_client/util"
)

Expand Down Expand Up @@ -79,9 +79,7 @@ func DeviceWhitelistKey(addr Address) []byte {
index := util.IntToBytes(DeviceWhitelistIndex)
padIndex := util.PaddingBytesPrefix(index, 0, 32)
padAddr := util.PaddingBytesPrefix(addr[:], 0, 32)
hash := sha3.NewKeccak256()
hash.Write(append(padAddr, padIndex...))
return hash.Sum(nil)
return crypto.Sha3Hash(append(padAddr, padIndex...))
}

// AccessWhitelistKey returns storage key of access whitelist of givin address
Expand All @@ -90,10 +88,6 @@ func AccessWhitelistKey(deviceAddr Address, clientAddr Address) []byte {
padIndex := util.PaddingBytesPrefix(index, 0, 32)
padDeviceAddr := util.PaddingBytesPrefix(deviceAddr[:], 0, 32)
padClientAddr := util.PaddingBytesPrefix(clientAddr[:], 0, 32)
hash := sha3.NewKeccak256()
hash.Write(append(padDeviceAddr, padIndex...))
baseKey := hash.Sum(nil)
hash = sha3.NewKeccak256()
hash.Write(append(padClientAddr, baseKey...))
return hash.Sum(nil)
baseKey := crypto.Sha3Hash(append(padDeviceAddr, padIndex...))
return crypto.Sha3Hash(append(padClientAddr, baseKey...))
}
6 changes: 2 additions & 4 deletions contract/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package contract

import (
"github.com/diodechain/diode_go_client/crypto/sha3"
"github.com/diodechain/diode_go_client/crypto"
"github.com/diodechain/diode_go_client/util"
)

Expand All @@ -24,7 +24,5 @@ func ContractStakeKey(addr []byte) []byte {
index := util.IntToBytes(ContractStakeIndex)
padIndex := util.PaddingBytesPrefix(index, 0, 32)
padAddr := util.PaddingBytesPrefix(addr, 0, 32)
hash := sha3.NewKeccak256()
hash.Write(append(padAddr, padIndex...))
return hash.Sum(nil)
return crypto.Sha3Hash(append(padAddr, padIndex...))
}
4 changes: 2 additions & 2 deletions crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"math/big"

"github.com/diodechain/diode_go_client/crypto/secp256k1"
"github.com/diodechain/diode_go_client/crypto/sha3"
"golang.org/x/crypto/sha3"
)

const ecPrivKeyVersion = 1
Expand Down Expand Up @@ -165,7 +165,7 @@ func Sha256(data []byte) []byte {

// Sha3Hash the data
func Sha3Hash(data []byte) []byte {
hash := sha3.NewKeccak256()
hash := sha3.NewLegacyKeccak256()
hash.Write(data)
return hash.Sum(nil)
}
Expand Down
27 changes: 0 additions & 27 deletions crypto/sha3/LICENSE

This file was deleted.

22 changes: 0 additions & 22 deletions crypto/sha3/PATENTS

This file was deleted.

66 changes: 0 additions & 66 deletions crypto/sha3/doc.go

This file was deleted.

71 changes: 0 additions & 71 deletions crypto/sha3/hashes.go

This file was deleted.

Loading

0 comments on commit 5a243f1

Please sign in to comment.