summary refs log tree commit diff
path: root/crypto/src/security
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-02-16 14:18:27 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-02-16 14:18:27 +0700
commita4f880422d022680673d6902bf6f5530cc544091 (patch)
treebfc5048253e0876780965b5af04121c3cc761105 /crypto/src/security
parentUpdate copyright (diff)
downloadBouncyCastle.NET-ed25519-a4f880422d022680673d6902bf6f5530cc544091.tar.xz
ParameterUtilities support for CCM, GCM parameters
- see https://github.com/bcgit/bc-csharp/issues/354
Diffstat (limited to 'crypto/src/security')
-rw-r--r--crypto/src/security/ParameterUtilities.cs25
1 files changed, 25 insertions, 0 deletions
diff --git a/crypto/src/security/ParameterUtilities.cs b/crypto/src/security/ParameterUtilities.cs
index d79f15359..d393e3d36 100644
--- a/crypto/src/security/ParameterUtilities.cs
+++ b/crypto/src/security/ParameterUtilities.cs
@@ -2,6 +2,7 @@ using System;
 using System.Collections.Generic;
 
 using Org.BouncyCastle.Asn1;
+using Org.BouncyCastle.Asn1.Cms;
 using Org.BouncyCastle.Asn1.CryptoPro;
 using Org.BouncyCastle.Asn1.Kisa;
 using Org.BouncyCastle.Asn1.Misc;
@@ -246,6 +247,30 @@ namespace Org.BouncyCastle.Security
             if (algorithm == null)
                 throw new ArgumentNullException("algorithm");
 
+            if (NistObjectIdentifiers.IdAes128Gcm.Id.Equals(algorithm) ||
+                NistObjectIdentifiers.IdAes192Gcm.Id.Equals(algorithm) ||
+                NistObjectIdentifiers.IdAes256Gcm.Id.Equals(algorithm))
+            {
+                if (!(key is KeyParameter keyParameter))
+                    throw new ArgumentException("key data must be accessible for GCM operation");
+
+                var gcmParameters = GcmParameters.GetInstance(asn1Params);
+
+                return new AeadParameters(keyParameter, gcmParameters.IcvLen * 8, gcmParameters.GetNonce());
+            }
+
+            if (NistObjectIdentifiers.IdAes128Ccm.Id.Equals(algorithm) ||
+                NistObjectIdentifiers.IdAes192Ccm.Id.Equals(algorithm) ||
+                NistObjectIdentifiers.IdAes256Ccm.Id.Equals(algorithm))
+            {
+                if (!(key is KeyParameter keyParameter))
+                    throw new ArgumentException("key data must be accessible for CCM operation");
+
+                var ccmParameters = CcmParameters.GetInstance(asn1Params);
+
+                return new AeadParameters(keyParameter, ccmParameters.IcvLen * 8, ccmParameters.GetNonce());
+            }
+
             string canonical = GetCanonicalAlgorithmName(algorithm);
 
             if (canonical == null)