FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go


Description:
crypto/cipher: panic on invalid iv length

Give better user feedback when invalid iv is used
to construct a cipher.

Fixes issue 3411

Please review this at http://codereview.appspot.com/6652053/

Affected files:
M src/pkg/crypto/cipher/cbc.go
M src/pkg/crypto/cipher/cfb.go


Index: src/pkg/crypto/cipher/cbc.go
===================================================================
--- a/src/pkg/crypto/cipher/cbc.go
+++ b/src/pkg/crypto/cipher/cbc.go
@@ -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))
}

Index: src/pkg/crypto/cipher/cfb.go
===================================================================
--- a/src/pkg/crypto/cipher/cfb.go
+++ b/src/pkg/crypto/cipher/cfb.go
@@ -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)
}

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedOct 12, '12 at 5:12a
activeOct 17, '12 at 6:29p
posts3
users2
websitegolang.org

2 users in discussion

Agl: 2 posts Shanemhansen: 1 post

People

Translate

site design / logo © 2022 Grokbase