summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2019-08-26 18:43:14 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2019-08-26 18:43:14 +0700
commit14c59956fa16106639ca3e17a0c89c200f7f17f6 (patch)
tree316a7113974cea654b28aed26887a8838e90bcdf /crypto/src
parentPssSigner verification improvements (diff)
downloadBouncyCastle.NET-ed25519-14c59956fa16106639ca3e17a0c89c200f7f17f6.tar.xz
Check CCM tag length during initialization
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/crypto/modes/CcmBlockCipher.cs12
1 files changed, 10 insertions, 2 deletions
diff --git a/crypto/src/crypto/modes/CcmBlockCipher.cs b/crypto/src/crypto/modes/CcmBlockCipher.cs

index fa97ec840..0e4bb7fc9 100644 --- a/crypto/src/crypto/modes/CcmBlockCipher.cs +++ b/crypto/src/crypto/modes/CcmBlockCipher.cs
@@ -68,7 +68,7 @@ namespace Org.BouncyCastle.Crypto.Modes nonce = param.GetNonce(); initialAssociatedText = param.GetAssociatedText(); - macSize = param.MacSize / 8; + macSize = GetMacSize(param.MacSize); cipherParameters = param.Key; } else if (parameters is ParametersWithIV) @@ -77,7 +77,7 @@ namespace Org.BouncyCastle.Crypto.Modes nonce = param.GetIV(); initialAssociatedText = null; - macSize = macBlock.Length / 2; + macSize = GetMacSize(64); cipherParameters = param.Parameters; } else @@ -434,6 +434,14 @@ namespace Org.BouncyCastle.Crypto.Modes return cMac.DoFinal(macBlock, 0); } + private int GetMacSize(int requestedMacBits) + { + if (requestedMacBits < 32 || requestedMacBits > 128 || 0 != (requestedMacBits & 15)) + throw new ArgumentException("tag length in octets must be one of {4,6,8,10,12,14,16}"); + + return requestedMacBits >> 3; + } + private int GetAssociatedTextLength() { return (int)associatedText.Length + ((initialAssociatedText == null) ? 0 : initialAssociatedText.Length);