Why "out" is needed in golang.org/x/crypto/nacl/box

Viewed 235

I started to use the package box in Go and got a little bit confused in Seal Function:

According to Documentation:

/*Seal appends an encrypted and authenticated copy of message to out, which will be Overhead
bytes longer than the original and must not overlap it. The nonce must be unique for each
distinct message for a given pair of keys. */

func Seal(out, message []byte, nonce *[24]byte, peersPublicKey, privateKey *[32]byte) []byte

But as we can see the func already returns a Byte Array containing encrypted and authenticated message

In the documentation, this func is used this way:

var nonce [24]byte
if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil {
    panic(err)
}

msg := []byte("Alas, poor Yorick! I knew him, Horatio")
// This encrypts msg and appends the result to the nonce.
encrypted := box.Seal(nonce[:], msg, &nonce, recipientPublicKey, senderPrivateKey)

So I have a few questions:

  • Why pass the values inside nonce, since nonce is the 3th argument?
  • Why "out" is needed?
0 Answers
Related