github.com/decred/dcrlnd@v0.7.6/fuzz/brontide/random_acttwo.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_random_acttwo is a go-fuzz harness for ActTwo in the brontide
    11  // handshake.
    12  func Fuzz_random_acttwo(data []byte) int {
    13  	// Check if data is large enough.
    14  	if len(data) < brontide.ActTwoSize {
    15  		return 1
    16  	}
    17  
    18  	// This will return brontide machines with random keys.
    19  	initiator, _ := getBrontideMachines()
    20  
    21  	// Generate ActOne - this isn't sent to the responder because nothing is
    22  	// done with the responder machine and this would slow down fuzzing.
    23  	// GenActOne needs to be called to set the appropriate state in the
    24  	// initiator machine.
    25  	_, err := initiator.GenActOne()
    26  	if err != nil {
    27  		nilAndPanic(initiator, nil, err)
    28  	}
    29  
    30  	// Copy data into [ActTwoSize]byte.
    31  	var actTwo [brontide.ActTwoSize]byte
    32  	copy(actTwo[:], data)
    33  
    34  	// Initiator receives ActTwo, should fail.
    35  	if err := initiator.RecvActTwo(actTwo); err == nil {
    36  		nilAndPanic(initiator, nil, nil)
    37  	}
    38  
    39  	return 1
    40  }