diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8859f82a..3518ea06 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,10 @@
*??? ??, ????*
+### CHANGES
+
+- `pkg/message/layer1`: GetHash(): HMAC(key, payload) -> Hash(payload)
+
## v1.7.13
diff --git a/pkg/message/layer1/message.go b/pkg/message/layer1/message.go
index fcc5cca2..2f12dbf7 100644
--- a/pkg/message/layer1/message.go
+++ b/pkg/message/layer1/message.go
@@ -40,12 +40,13 @@ type sMessage struct {
func NewMessage(pSett IConstructSettings, pPld payload.IPayload32) IMessage {
sett := pSett.GetSettings()
pldBytes := pPld.ToBytes()
+ hash := hashing.NewHasher(pldBytes).ToBytes()
keyBuilder := keybuilder.NewKeyBuilder(0, []byte{}) // the network_key must have good entropy
key := keyBuilder.Build(sett.GetNetworkKey(), symmetric.CCipherKeySize)
- hash := hashing.NewHMACHasher(key, pldBytes).ToBytes()
+ netHash := hashing.NewHMACHasher(key, hash).ToBytes()
- proof := puzzle.NewPoWPuzzle(sett.GetWorkSizeBits()).ProofBytes(hash, pSett.GetParallel())
+ proof := puzzle.NewPoWPuzzle(sett.GetWorkSizeBits()).ProofBytes(netHash, pSett.GetParallel())
proofBytes := encoding.Uint64ToBytes(proof)
cipher := symmetric.NewCipher(key)
@@ -53,7 +54,7 @@ func NewMessage(pSett IConstructSettings, pPld payload.IPayload32) IMessage {
fEncd: cipher.EncryptBytes(bytes.Join(
[][]byte{
proofBytes[:],
- hash,
+ netHash,
pldBytes,
},
[]byte{},
@@ -88,14 +89,15 @@ func LoadMessage(pSett ISettings, pData interface{}) (IMessage, error) {
copy(proofArr[:], dBytes[:cProofIndex])
proof := encoding.BytesToUint64(proofArr)
- hash := dBytes[cProofIndex:cHashIndex]
+ netHash := dBytes[cProofIndex:cHashIndex]
puzzle := puzzle.NewPoWPuzzle(pSett.GetWorkSizeBits())
- if !puzzle.VerifyBytes(hash, proof) {
+ if !puzzle.VerifyBytes(netHash, proof) {
return nil, ErrInvalidProofOfWork
}
- newHash := hashing.NewHMACHasher(key, dBytes[cHashIndex:]).ToBytes()
- if !bytes.Equal(hash, newHash) {
+ hash := hashing.NewHasher(dBytes[cHashIndex:]).ToBytes()
+ newNetHash := hashing.NewHMACHasher(key, hash).ToBytes()
+ if !bytes.Equal(netHash, newNetHash) {
return nil, ErrInvalidAuthHash
}
diff --git a/pkg/message/layer1/message_test.go b/pkg/message/layer1/message_test.go
index d822a6f4..300e9d98 100644
--- a/pkg/message/layer1/message_test.go
+++ b/pkg/message/layer1/message_test.go
@@ -99,9 +99,7 @@ func TestMessage(t *testing.T) {
return
}
- keyBuilder := keybuilder.NewKeyBuilder(0, []byte{}) // the network_key must have good entropy
- key := keyBuilder.Build(tcNetworkKey, symmetric.CCipherKeySize)
- newHash := hashing.NewHMACHasher(key, pld.ToBytes()).ToBytes()
+ newHash := hashing.NewHasher(pld.ToBytes()).ToBytes()
if !bytes.Equal(msg.GetHash(), newHash) {
t.Error("payload hash not equal hash of message")
return
diff --git a/pkg/message/layer1/types.go b/pkg/message/layer1/types.go
index 2267d637..048a1bd2 100644
--- a/pkg/message/layer1/types.go
+++ b/pkg/message/layer1/types.go
@@ -8,14 +8,14 @@ import (
type IMessage interface {
types.IConverter
- // hash = HMAC(network_key, payload)
- GetHash() []byte
-
- // proof = PoW(hash)
- GetProof() uint64
-
// payload = head(32bit) || body(Nbit)
GetPayload() payload.IPayload32
+
+ // hash = H(payload)
+ GetHash() []byte
+
+ // proof = PoW(HMAC(network_key, hash))
+ GetProof() uint64
}
type IConstructSettings interface {
diff --git a/test/result/coverage.svg b/test/result/coverage.svg
index 9040eaa8..b0ac7036 100644
--- a/test/result/coverage.svg
+++ b/test/result/coverage.svg
@@ -7,7 +7,7 @@
>
-
+
-
+
-
+
-
+
-
+
crypto
@@ -65,12 +65,12 @@
-
+
encoding
@@ -78,12 +78,12 @@
-
+
logger
@@ -91,12 +91,12 @@
-
+
message
@@ -104,12 +104,12 @@
-
+
network
@@ -117,12 +117,12 @@
-
+
payload
@@ -130,12 +130,12 @@
-
+
state
@@ -143,12 +143,12 @@
-
+
storage
@@ -156,12 +156,12 @@
-
+
action.go
@@ -169,13 +169,13 @@
-
+
-
+
-
+
-
+
head.go
@@ -207,12 +207,12 @@
-
+
logger/log_builder.go
@@ -220,7 +220,7 @@
-
+
-
+
settings.go
@@ -246,12 +246,12 @@
-
+
asymmetric
@@ -259,12 +259,12 @@
-
+
hashing
@@ -272,12 +272,12 @@
-
+
hybrid/client
@@ -285,18 +285,18 @@
-
+
-
+
puzzle/puzzle.go
@@ -304,12 +304,12 @@
-
+
random/random.go
@@ -317,12 +317,12 @@
-
+
symmetric/symmetric.go
@@ -330,12 +330,12 @@
-
+
bytes.go
@@ -343,18 +343,18 @@
-
+
-
+
hex.go
@@ -362,12 +362,12 @@
-
+
serialize_json.go
@@ -375,18 +375,18 @@
-
+
-
+
logger.go
@@ -394,18 +394,18 @@
-
+
-
+
layer1
@@ -413,12 +413,12 @@
-
+
layer2
@@ -426,12 +426,12 @@
-
+
conn
@@ -439,12 +439,12 @@
-
+
connkeeper
@@ -452,12 +452,12 @@
-
+
network.go
@@ -465,12 +465,12 @@
-
+
settings.go
@@ -478,12 +478,12 @@
-
+
joiner
@@ -491,12 +491,12 @@
-
+
payload32.go
@@ -504,12 +504,12 @@
-
+
payload64.go
@@ -517,12 +517,12 @@
-
+
state.go
@@ -530,12 +530,12 @@
-
+
cache/lru.go
@@ -543,12 +543,12 @@
-
+
database
@@ -556,13 +556,13 @@
-
+
-
+
-
+
-
+
dsa.go
@@ -594,12 +594,12 @@
-
+
kem.go
@@ -607,12 +607,12 @@
-
+
key.go
@@ -620,12 +620,12 @@
-
+
map_pubkeys.go
@@ -633,12 +633,12 @@
-
+
hashing.go
@@ -646,12 +646,12 @@
-
+
hmac.go
@@ -659,12 +659,12 @@
-
+
client.go
@@ -672,18 +672,18 @@
-
+
-
+
message.go
@@ -691,12 +691,12 @@
-
+
settings.go
@@ -704,12 +704,12 @@
-
+
message.go
@@ -717,12 +717,12 @@
-
+
conn.go
@@ -730,12 +730,12 @@
-
+
settings.go
@@ -743,12 +743,12 @@
-
+
connkeeper.go
@@ -756,12 +756,12 @@
-
+
settings.go
@@ -769,18 +769,18 @@
-
+
-
+
database.go