This commit is contained in:
number571 2024-04-16 04:18:24 +07:00
parent 9c747f634f
commit 79100b5914
5 changed files with 43829 additions and 43811 deletions

View File

@ -8,6 +8,10 @@
- Update `cmd/hidden_lake/adapters`: producer, consumer apps -> one app
### BUG FIXES
- Update `pkg/network/message`: fix GetVoid bytes method
## v1.6.8
*April 07, 2024*

File diff suppressed because it is too large Load Diff

View File

@ -13,12 +13,18 @@ import (
)
const (
// Salt = 128bit
cSaltSize = 16
// Salt(cipher) + Salt(auth) + IV + Hash + Proof + PayloadSize + PayloadHead
cSaltSize = 16
CMessageHeadSize = 2*cSaltSize +
CMessageHeadSize = 0 +
cSaltSize +
cSaltSize +
symmetric.CAESBlockSize +
hashing.CSHA256Size +
3*encoding.CSizeUint64
encoding.CSizeUint64 +
encoding.CSizeUint64 +
encoding.CSizeUint64
)
var (
@ -131,17 +137,20 @@ func LoadMessage(pSett ISettings, pData interface{}) (IMessage, error) {
return nil, ErrInvalidProofOfWork
}
payloadVoidBytes := pphpBytes[hashIndex:]
if (payloadLength + encoding.CSizeUint64) > uint64(len(payloadVoidBytes)) {
lenPayloadVoidBytes := pphpBytes[hashIndex:]
if (payloadLength + encoding.CSizeUint64) > uint64(len(lenPayloadVoidBytes)) {
return nil, ErrInvalidPayloadSize
}
newHash := getAuthHash(pSett.GetNetworkKey(), authSaltBytes, payloadVoidBytes)
newHash := getAuthHash(pSett.GetNetworkKey(), authSaltBytes, lenPayloadVoidBytes)
if !bytes.Equal(hash, newHash) {
return nil, ErrInvalidAuthHash
}
payloadBytes := payloadVoidBytes[encoding.CSizeUint64:][:payloadLength]
payloadVoidBytes := lenPayloadVoidBytes[encoding.CSizeUint64:]
payloadBytes := payloadVoidBytes[:payloadLength]
voidBytes := payloadVoidBytes[payloadLength:]
payload := payload.LoadPayload(payloadBytes)
if payload == nil {
return nil, ErrDecodePayload
@ -154,7 +163,7 @@ func LoadMessage(pSett ISettings, pData interface{}) (IMessage, error) {
},
fEncPPHP: encPPHPBytes,
fHash: hash,
fVoid: payloadVoidBytes[payloadLength:],
fVoid: voidBytes,
fProof: proof,
fPayload: payload,
}, nil

View File

@ -66,6 +66,11 @@ func TestMessage(t *testing.T) {
return
}
if (len(msg.ToBytes()) - len(voidBytes)) != len(msg.GetPayload().GetBody())+CMessageHeadSize {
t.Error("invalid message size in bytes with void")
return
}
payloadSize := encoding.Uint64ToBytes(uint64(len(pld.ToBytes())))
payloadRandBytes := bytes.Join(
[][]byte{payloadSize[:], pld.ToBytes(), voidBytes},

File diff suppressed because it is too large Load Diff