whisper: sym encryption message padding includes salt

This commit is contained in:
Guillaume Ballet 2017-12-08 20:35:39 +01:00
parent bf62acf033
commit 4535c5f250
2 changed files with 26 additions and 0 deletions

View file

@ -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

View file

@ -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))
}
}