mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
whisper: sym encryption message padding includes salt
This commit is contained in:
parent
bf62acf033
commit
4535c5f250
2 changed files with 26 additions and 0 deletions
|
|
@ -123,6 +123,8 @@ func (msg *sentMessage) appendPadding(params *MessageParams) error {
|
|||
rawSize := len(params.Payload) + 1
|
||||
if params.Src != nil {
|
||||
rawSize += signatureLength
|
||||
} else {
|
||||
rawSize += AESNonceLength
|
||||
}
|
||||
odd := rawSize % padSizeLimit
|
||||
|
||||
|
|
|
|||
|
|
@ -416,3 +416,27 @@ func TestPadding(t *testing.T) {
|
|||
singlePaddingTest(t, n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPaddingAppendedToSymMessages(t *testing.T) {
|
||||
params := &MessageParams{
|
||||
Payload: make([]byte, 246),
|
||||
KeySym: make([]byte, aesKeyLength),
|
||||
}
|
||||
|
||||
// Simulate a message with a payload just under 256 so that
|
||||
// payload + flag + aesnonce > 256. Check that the result
|
||||
// is padded on the next 256 boundary.
|
||||
msg := sentMessage{}
|
||||
msg.Raw = make([]byte, len(params.Payload)+1+AESNonceLength)
|
||||
|
||||
err := msg.appendPadding(params)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error appending padding to message %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(msg.Raw) != 512 {
|
||||
t.Errorf("Invalid size %d != 512", len(msg.Raw))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue