Data is encrypted with a block cipher directly, without a mode of operation
What it finds
block, _ := aes.NewCipher(key); block.Encrypt(dst, src): a block cipher used directly encrypts one block on its own, and applied block by block it turns equal blocks of the message into equal blocks of ciphertext, which shows its structure. An authenticated mode such as cipher.NewGCM(block) encrypts whole messages safely.
Reported is a call of Encrypt or Decrypt on a variable declared with the result of aes.NewCipher, des.NewCipher or des.NewTripleDESCipher.
From the rule's source, raw_block_encryption.rs.
package p import ( "crypto/aes" "crypto/cipher") func seal(key, dst, src []byte) error { block, err := aes.NewCipher(key) if err != nil { return err } block.Encrypt(dst, src)tx0 reports: the block cipher is applied directly, one block at a time gcm, err := cipher.NewGCM(block) if err != nil { return err } gcm.Seal(dst[:0], src[:12], src, nil) return nil} 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:
[rules]
"tx0/go:raw-block-encryption" = "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:raw-block-encryption] reason="..."tx0 explain tx0/go:raw-block-encryption shows the same in the terminal. Found a false positive? Report it.