Blake2b/s: relax length-only constructor constraints
- addresses https://github.com/bcgit/bc-csharp/issues/142
2 files changed, 5 insertions, 6 deletions
diff --git a/crypto/src/crypto/digests/Blake2bDigest.cs b/crypto/src/crypto/digests/Blake2bDigest.cs
index b8e4f272e..770e35caf 100644
--- a/crypto/src/crypto/digests/Blake2bDigest.cs
+++ b/crypto/src/crypto/digests/Blake2bDigest.cs
@@ -136,8 +136,8 @@ namespace Org.BouncyCastle.Crypto.Digests
*/
public Blake2bDigest(int digestSize)
{
- if (digestSize != 160 && digestSize != 256 && digestSize != 384 && digestSize != 512)
- throw new ArgumentException("BLAKE2b digest restricted to one of [160, 256, 384, 512]");
+ if (digestSize < 8 || digestSize > 512 || digestSize % 8 != 0)
+ throw new ArgumentException("BLAKE2b digest bit length must be a multiple of 8 and not greater than 512");
buffer = new byte[BLOCK_LENGTH_BYTES];
keyLength = 0;
diff --git a/crypto/src/crypto/digests/Blake2sDigest.cs b/crypto/src/crypto/digests/Blake2sDigest.cs
index f31032874..432b0f4d2 100644
--- a/crypto/src/crypto/digests/Blake2sDigest.cs
+++ b/crypto/src/crypto/digests/Blake2sDigest.cs
@@ -152,13 +152,12 @@ namespace Org.BouncyCastle.Crypto.Digests
/**
* BLAKE2s for hashing.
*
- * @param digestBits the desired digest length in bits. Must be one of
- * [128, 160, 224, 256].
+ * @param digestBits the desired digest length in bits. Must be a multiple of 8 and less than 256.
*/
public Blake2sDigest(int digestBits)
{
- if (digestBits != 128 && digestBits != 160 && digestBits != 224 && digestBits != 256)
- throw new ArgumentException("BLAKE2s digest restricted to one of [128, 160, 224, 256]");
+ if (digestBits < 8 || digestBits > 256 || digestBits % 8 != 0)
+ throw new ArgumentException("BLAKE2s digest bit length must be a multiple of 8 and not greater than 256");
buffer = new byte[BLOCK_LENGTH_BYTES];
keyLength = 0;
|