diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2018-09-16 17:09:50 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2018-09-16 17:09:50 +0700 |
commit | af7355a81832318dd9b3125be82c12389ec0cb90 (patch) | |
tree | f74d46d08aae3daf979437d035c72f4c9ea659f0 /crypto/src | |
parent | Fixed Rfc3211WrapEngine processing of messages over 127 bytes. (diff) | |
download | BouncyCastle.NET-ed25519-af7355a81832318dd9b3125be82c12389ec0cb90.tar.xz |
Blake2b/s: relax length-only constructor constraints
- addresses https://github.com/bcgit/bc-csharp/issues/142
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/crypto/digests/Blake2bDigest.cs | 4 | ||||
-rw-r--r-- | crypto/src/crypto/digests/Blake2sDigest.cs | 7 |
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; |