From 1d0f6346030e5c01a69e6e3659c3238ab7e5e857 Mon Sep 17 00:00:00 2001 From: David Hook Date: Mon, 31 May 2021 08:54:59 +1000 Subject: github #172 - added blowfish init check on key size --- crypto/test/src/crypto/test/BlowfishTest.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'crypto/test/src') diff --git a/crypto/test/src/crypto/test/BlowfishTest.cs b/crypto/test/src/crypto/test/BlowfishTest.cs index 780dd3abd..b940d13ac 100644 --- a/crypto/test/src/crypto/test/BlowfishTest.cs +++ b/crypto/test/src/crypto/test/BlowfishTest.cs @@ -40,6 +40,29 @@ namespace Org.BouncyCastle.Crypto.Tests { string resultText = Perform().ToString(); + BlowfishEngine blowfish = new BlowfishEngine(); + + // key range check + try + { + blowfish.Init(true, new KeyParameter(new byte[1])); + Fail("no exception"); + } + catch (ArgumentException e) + { + Assert.AreEqual("key length must be in range 32 to 448 bits", e.Message); + } + + try + { + blowfish.Init(true, new KeyParameter(new byte[59])); + Fail("no exception"); + } + catch (ArgumentException e) + { + Assert.AreEqual("key length must be in range 32 to 448 bits", e.Message); + } + Assert.AreEqual(Name + ": Okay", resultText); } -- cgit 1.5.1