Data is encrypted with an initialization vector or nonce that is the same every time

tx0/go:constant-ivrecommendedwarningsecurity, cwe-329

What it finds

cipher.NewCBCEncrypter(block, []byte("0123456789abcdef")): the initialization vector or nonce of a cipher mode must differ for every message encrypted with the same key. With a fixed one, equal messages encrypt to equal ciphertexts, and in CTR, OFB and GCM two messages under the same nonce reveal their XOR, or let a forger sign anything. IVs come from crypto/rand and travel with the ciphertext.

Reported are IVs and nonces that are constant bytes, as described for constant byte values of the pack: given to NewCBCEncrypter, NewCFBEncrypter, NewCTR or NewOFB of crypto/cipher, resolved through the imports, or as the nonce of a method Seal in a file that imports crypto/cipher.

From the rule's source, constant_iv.rs.

Example from the rule's tests
package p import (	"crypto/aes"	"crypto/cipher"	"crypto/rand") func encrypt(key, data []byte) []byte {	block, _ := aes.NewCipher(key)	out := make([]byte, len(data))	cipher.NewCBCEncrypter(block, []byte("0123456789abcdef")).CryptBlocks(out, data)tx0 reports: the IV or nonce is the same for every message	zero := make([]byte, aes.BlockSize)	cipher.NewCTR(block, zero).XORKeyStream(out, data)tx0 reports: the IV or nonce is the same for every message	iv := make([]byte, aes.BlockSize)	rand.Read(iv)	cipher.NewCTR(block, iv).XORKeyStream(out, data)	gcm, _ := cipher.NewGCM(block)	return gcm.Seal(nil, []byte("fixed-nonce!"), data, nil)tx0 reports: the IV or nonce is the same for every message}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:constant-iv" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/go:constant-iv] reason="..."

tx0 explain tx0/go:constant-iv shows the same in the terminal. Found a false positive? Report it.