Revision: d588fe3d90c8
Branch: default
Author: Shane Hansen <
shanem...@gmail.com>
Date: Wed Oct 17 11:29:00 2012
Log: crypto/cipher: panic on invalid IV length
Give better user feedback when invalid IV is used
to construct a cipher.
Fixes issue 3411
R=golang-dev, agl
CC=golang-dev
http://codereview.appspot.com/6652053
Committer: Adam Langley <
a...@golang.org>
http://code.google.com/p/go/source/detail?r=d588fe3d90c8
Modified:
/src/pkg/crypto/cipher/cbc.go
/src/pkg/crypto/cipher/cfb.go
/src/pkg/crypto/cipher/ctr.go
=======================================
--- /src/pkg/crypto/cipher/cbc.go Fri Feb 3 12:08:53 2012
+++ /src/pkg/crypto/cipher/cbc.go Wed Oct 17 11:29:00 2012
@@ -33,6 +33,9 @@
// mode, using the given Block. The length of iv must be the same as the
// Block's block size.
func NewCBCEncrypter(b Block, iv []byte) BlockMode {
+ if len(iv) != b.BlockSize() {
+ panic("cipher.NewCBCEncrypter: IV length must equal block size")
+ }
return (*cbcEncrypter)(newCBC(b, iv))
}
@@ -58,6 +61,9 @@
// mode, using the given Block. The length of iv must be the same as the
// Block's block size and must match the iv used to encrypt the data.
func NewCBCDecrypter(b Block, iv []byte) BlockMode {
+ if len(iv) != b.BlockSize() {
+ panic("cipher.NewCBCDecrypter: IV length must equal block size")
+ }
return (*cbcDecrypter)(newCBC(b, iv))
}
=======================================
--- /src/pkg/crypto/cipher/cfb.go Fri Nov 19 13:17:58 2010
+++ /src/pkg/crypto/cipher/cfb.go Wed Oct 17 11:29:00 2012
@@ -17,6 +17,9 @@
// using the given Block. The iv must be the same length as the Block's
block
// size.
func NewCFBEncrypter(block Block, iv []byte) Stream {
+ if len(iv) != block.BlockSize() {
+ panic("cipher.NewCBFEncrypter: IV length must equal block size")
+ }
return newCFB(block, iv, false)
}
@@ -24,6 +27,9 @@
// using the given Block. The iv must be the same length as the Block's
block
// size.
func NewCFBDecrypter(block Block, iv []byte) Stream {
+ if len(iv) != block.BlockSize() {
+ panic("cipher.NewCBFEncrypter: IV length must equal block size")
+ }
return newCFB(block, iv, true)
}
=======================================
--- /src/pkg/crypto/cipher/ctr.go Tue Mar 29 12:47:35 2011
+++ /src/pkg/crypto/cipher/ctr.go Wed Oct 17 11:29:00 2012
@@ -23,7 +23,7 @@
// counter mode. The length of iv must be the same as the Block's block
size.
func NewCTR(block Block, iv []byte) Stream {
if len(iv) != block.BlockSize() {
- panic("cipher.NewCTR: iv length must equal block size")
+ panic("cipher.NewCTR: IV length must equal block size")
}
return &ctr{