github.com/decred/dcrlnd@v0.7.6/fuzz/brontide/static_init_encrypt.go (about)

     1  //go:build gofuzz
     2  // +build gofuzz
     3  
     4  package brontidefuzz
     5  
     6  import (
     7  	"bytes"
     8  	"math"
     9  )
    10  
    11  // Fuzz_static_init_encrypt is a go-fuzz harness that encrypts arbitrary data
    12  // with the initiator.
    13  func Fuzz_static_init_encrypt(data []byte) int {
    14  	// Ensure that length of message is not greater than max allowed size.
    15  	if len(data) > math.MaxUint16 {
    16  		return 1
    17  	}
    18  
    19  	// This will return brontide machines with static keys.
    20  	initiator, responder := getStaticBrontideMachines()
    21  
    22  	// Complete the brontide handshake.
    23  	completeHandshake(initiator, responder)
    24  
    25  	var b bytes.Buffer
    26  
    27  	// Encrypt the message using WriteMessage w/ initiator machine.
    28  	if err := initiator.WriteMessage(data); err != nil {
    29  		nilAndPanic(initiator, responder, err)
    30  	}
    31  
    32  	// Flush the encrypted message w/ initiator machine.
    33  	if _, err := initiator.Flush(&b); err != nil {
    34  		nilAndPanic(initiator, responder, err)
    35  	}
    36  
    37  	return 1
    38  }