aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisperv5/envelope.go
diff options
context:
space:
mode:
authorgluk256 <gluk256@users.noreply.github.com>2017-04-27 03:05:48 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-04-27 03:05:48 +0800
commit95f0bd0acf301bf8415747c4ff050e8a4dfdc864 (patch)
tree13edad970fb30a8e12151b2ec1a443b0ad970d2b /whisper/whisperv5/envelope.go
parent8dce4c283dda3a8e10aa30dadab05a8c0dd9e19d (diff)
downloaddexon-95f0bd0acf301bf8415747c4ff050e8a4dfdc864.tar.gz
dexon-95f0bd0acf301bf8415747c4ff050e8a4dfdc864.tar.zst
dexon-95f0bd0acf301bf8415747c4ff050e8a4dfdc864.zip
whisper: message format refactoring (#14335)
* whisper: salt removed from AES encryption * whisper: padding format updated * whisper: padding test added * whisper: padding refactored, tests fixed * whisper: padding test updated * whisper: wnode bugfix * whisper: send/receive protocol updated * whisper: minor update * whisper: bugfix in test * whisper: updated parameter names and comments * whisper: functions renamed * whisper: minor refactoring
Diffstat (limited to 'whisper/whisperv5/envelope.go')
-rw-r--r--whisper/whisperv5/envelope.go27
1 files changed, 13 insertions, 14 deletions
diff --git a/whisper/whisperv5/envelope.go b/whisper/whisperv5/envelope.go
index dffa7b286..d95fcab75 100644
--- a/whisper/whisperv5/envelope.go
+++ b/whisper/whisperv5/envelope.go
@@ -40,7 +40,6 @@ type Envelope struct {
Expiry uint32
TTL uint32
Topic TopicType
- Salt []byte
AESNonce []byte
Data []byte
EnvNonce uint64
@@ -50,15 +49,25 @@ type Envelope struct {
// Don't access hash directly, use Hash() function instead.
}
+// size returns the size of envelope as it is sent (i.e. public fields only)
+func (e *Envelope) size() int {
+ return 20 + len(e.Version) + len(e.AESNonce) + len(e.Data)
+}
+
+// rlpWithoutNonce returns the RLP encoded envelope contents, except the nonce.
+func (e *Envelope) rlpWithoutNonce() []byte {
+ res, _ := rlp.EncodeToBytes([]interface{}{e.Version, e.Expiry, e.TTL, e.Topic, e.AESNonce, e.Data})
+ return res
+}
+
// NewEnvelope wraps a Whisper message with expiration and destination data
// included into an envelope for network forwarding.
-func NewEnvelope(ttl uint32, topic TopicType, salt []byte, aesNonce []byte, msg *SentMessage) *Envelope {
+func NewEnvelope(ttl uint32, topic TopicType, aesNonce []byte, msg *SentMessage) *Envelope {
env := Envelope{
Version: make([]byte, 1),
Expiry: uint32(time.Now().Add(time.Second * time.Duration(ttl)).Unix()),
TTL: ttl,
Topic: topic,
- Salt: salt,
AESNonce: aesNonce,
Data: msg.Raw,
EnvNonce: 0,
@@ -126,10 +135,6 @@ func (e *Envelope) Seal(options *MessageParams) error {
return nil
}
-func (e *Envelope) size() int {
- return len(e.Data) + len(e.Version) + len(e.AESNonce) + len(e.Salt) + 20
-}
-
func (e *Envelope) PoW() float64 {
if e.pow == 0 {
e.calculatePoW(0)
@@ -159,12 +164,6 @@ func (e *Envelope) powToFirstBit(pow float64) int {
return int(bits)
}
-// rlpWithoutNonce returns the RLP encoded envelope contents, except the nonce.
-func (e *Envelope) rlpWithoutNonce() []byte {
- res, _ := rlp.EncodeToBytes([]interface{}{e.Expiry, e.TTL, e.Topic, e.Salt, e.AESNonce, e.Data})
- return res
-}
-
// Hash returns the SHA3 hash of the envelope, calculating it if not yet done.
func (e *Envelope) Hash() common.Hash {
if (e.hash == common.Hash{}) {
@@ -210,7 +209,7 @@ func (e *Envelope) OpenAsymmetric(key *ecdsa.PrivateKey) (*ReceivedMessage, erro
// OpenSymmetric tries to decrypt an envelope, potentially encrypted with a particular key.
func (e *Envelope) OpenSymmetric(key []byte) (msg *ReceivedMessage, err error) {
msg = &ReceivedMessage{Raw: e.Data}
- err = msg.decryptSymmetric(key, e.Salt, e.AESNonce)
+ err = msg.decryptSymmetric(key, e.AESNonce)
if err != nil {
msg = nil
}