mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 18:10:34 +01:00
f82653cb06
This allows gofuzz to store the mutating input as coverage if it reaches any new coverage, even if it didn't make it to the end of the test.
38 lines
873 B
Go
38 lines
873 B
Go
// +build gofuzz
|
|
|
|
package brontidefuzz
|
|
|
|
import (
|
|
"bytes"
|
|
"math"
|
|
)
|
|
|
|
// Fuzz_static_init_encrypt is a go-fuzz harness that encrypts arbitrary data
|
|
// with the initiator.
|
|
func Fuzz_static_init_encrypt(data []byte) int {
|
|
// Ensure that length of message is not greater than max allowed size.
|
|
if len(data) > math.MaxUint16 {
|
|
return 1
|
|
}
|
|
|
|
// This will return brontide machines with static keys.
|
|
initiator, responder := getStaticBrontideMachines()
|
|
|
|
// Complete the brontide handshake.
|
|
completeHandshake(initiator, responder)
|
|
|
|
var b bytes.Buffer
|
|
|
|
// Encrypt the message using WriteMessage w/ initiator machine.
|
|
if err := initiator.WriteMessage(data); err != nil {
|
|
nilAndPanic(initiator, responder, err)
|
|
}
|
|
|
|
// Flush the encrypted message w/ initiator machine.
|
|
if _, err := initiator.Flush(&b); err != nil {
|
|
nilAndPanic(initiator, responder, err)
|
|
}
|
|
|
|
return 1
|
|
}
|