From 16edf0b1f7401df07e0d2f96c8b97516e50cffd9 Mon Sep 17 00:00:00 2001 From: Joe Kyo Date: Wed, 6 Sep 2017 10:31:03 +0100 Subject: [PATCH] crypto/cipher: panic when IV length does not equal block size in NewOFB Functions like NewCBCDecrypter, NewCBCEncrypter, NewCFBDecrypter, NewCFBEncrypter and NewCTR all panic when IV length does not equal block size. This commit changes NewOFB to panic too, instead of returning nil silently. Change-Id: Ic4d3ebfad79bb0cf4759fa1c1a400c1a8d043490 Reviewed-on: https://go-review.googlesource.com/61850 Reviewed-by: Filippo Valsorda Run-TryBot: Filippo Valsorda TryBot-Result: Gobot Gobot --- src/crypto/cipher/ofb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/cipher/ofb.go b/src/crypto/cipher/ofb.go index e86ebcb237e..7b35f8995c8 100644 --- a/src/crypto/cipher/ofb.go +++ b/src/crypto/cipher/ofb.go @@ -19,7 +19,7 @@ type ofb struct { func NewOFB(b Block, iv []byte) Stream { blockSize := b.BlockSize() if len(iv) != blockSize { - return nil + panic("cipher.NewOFB: IV length must equal block size") } bufSize := streamBufferSize if bufSize < blockSize {