github.com/decred/dcrlnd@v0.7.6/fuzz/brontide/static_actthree.go (about) 1 //go:build gofuzz 2 // +build gofuzz 3 4 package brontidefuzz 5 6 import ( 7 "github.com/decred/dcrlnd/brontide" 8 ) 9 10 // Fuzz_static_actthree is a go-fuzz harness for ActThree in the brontide 11 // handshake. 12 func Fuzz_static_actthree(data []byte) int { 13 // Check if data is large enough. 14 if len(data) < brontide.ActThreeSize { 15 return 1 16 } 17 18 // This will return brontide machines with static keys. 19 initiator, responder := getStaticBrontideMachines() 20 21 // Generate ActOne and send to the responder. 22 actOne, err := initiator.GenActOne() 23 if err != nil { 24 nilAndPanic(initiator, responder, err) 25 } 26 27 // Receiving ActOne should succeed, so we panic on error. 28 if err := responder.RecvActOne(actOne); err != nil { 29 nilAndPanic(initiator, responder, err) 30 } 31 32 // Generate ActTwo - this is not sent to the initiator because nothing is 33 // done with the initiator after this point and it would slow down fuzzing. 34 // GenActTwo needs to be called to set the appropriate state in the responder 35 // machine. 36 _, err = responder.GenActTwo() 37 if err != nil { 38 nilAndPanic(initiator, responder, err) 39 } 40 41 // Copy data into [ActThreeSize]byte. 42 var actThree [brontide.ActThreeSize]byte 43 copy(actThree[:], data) 44 45 // Responder receives ActThree, should fail. 46 if err := responder.RecvActThree(actThree); err == nil { 47 nilAndPanic(initiator, responder, nil) 48 } 49 50 return 1 51 }