summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-02-14 18:55:52 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-02-14 18:55:52 +0700
commit708e5543f380a85d1d7ef7ec1c35c3d7e6e5e02f (patch)
tree99a36474768e20235ccc2778c548217535bdfaa3
parentRefactor Check (diff)
downloadBouncyCastle.NET-ed25519-708e5543f380a85d1d7ef7ec1c35c3d7e6e5e02f.tar.xz
Update WrapperUtilities algorithms
-rw-r--r--crypto/src/crypto/engines/AriaWrapEngine.cs30
-rw-r--r--crypto/src/security/WrapperUtilities.cs57
2 files changed, 76 insertions, 11 deletions
diff --git a/crypto/src/crypto/engines/AriaWrapEngine.cs b/crypto/src/crypto/engines/AriaWrapEngine.cs
new file mode 100644
index 000000000..94327a659
--- /dev/null
+++ b/crypto/src/crypto/engines/AriaWrapEngine.cs
@@ -0,0 +1,30 @@
+namespace Org.BouncyCastle.Crypto.Engines
+{
+    /// <remarks>
+    /// An implementation of the ARIA Key Wrapper from the NIST Key Wrap Specification.
+    /// <p/>
+    /// For further details see: <a href="http://csrc.nist.gov/encryption/kms/key-wrap.pdf">http://csrc.nist.gov/encryption/kms/key-wrap.pdf</a>.
+    /// </remarks>
+    public class AriaWrapEngine
+		: Rfc3394WrapEngine
+	{
+        /// <summary>
+        /// Create a regular AriaWrapEngine specifying the encrypt for wrapping, decrypt for unwrapping.
+        /// </summary>
+        public AriaWrapEngine()
+			: base(new AriaEngine())
+		{
+		}
+
+        /// <summary>
+        /// Create an AriaWrapEngine where the underlying cipher is (optionally) set to decrypt for wrapping, encrypt for
+        /// unwrapping.
+        /// </summary>
+        /// <param name="useReverseDirection">true if underlying cipher should be used in decryption mode, false
+        /// otherwise.</param>
+        public AriaWrapEngine(bool useReverseDirection)
+            : base(new AriaEngine(), useReverseDirection)
+        {
+        }
+    }
+}
diff --git a/crypto/src/security/WrapperUtilities.cs b/crypto/src/security/WrapperUtilities.cs
index 74e13f121..e7383a054 100644
--- a/crypto/src/security/WrapperUtilities.cs
+++ b/crypto/src/security/WrapperUtilities.cs
@@ -4,6 +4,7 @@ using System.Collections.Generic;
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Kisa;
 using Org.BouncyCastle.Asn1.Nist;
+using Org.BouncyCastle.Asn1.Nsri;
 using Org.BouncyCastle.Asn1.Ntt;
 using Org.BouncyCastle.Asn1.Pkcs;
 using Org.BouncyCastle.Crypto;
@@ -18,8 +19,20 @@ namespace Org.BouncyCastle.Security
     /// </remarks>
     public static class WrapperUtilities
     {
-        private enum WrapAlgorithm { AESWRAP, CAMELLIAWRAP, DESEDEWRAP, RC2WRAP, SEEDWRAP,
-            DESEDERFC3211WRAP, AESRFC3211WRAP, CAMELLIARFC3211WRAP };
+        private enum WrapAlgorithm
+        {
+            AESRFC3211WRAP,
+            AESWRAP,
+            ARIARFC3211WRAP,
+            ARIAWRAP,
+            CAMELLIARFC3211WRAP,
+            CAMELLIAWRAP,
+            DESRFC3211WRAP,
+            DESEDERFC3211WRAP,
+            DESEDEWRAP,
+            RC2WRAP,
+            SEEDWRAP,
+        };
 
         private static readonly IDictionary<string, string> Algorithms =
             new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
@@ -29,19 +42,27 @@ namespace Org.BouncyCastle.Security
             // Signal to obfuscation tools not to change enum constants
             Enums.GetArbitraryValue<WrapAlgorithm>().ToString();
 
+            Algorithms["AESKW"] = "AESWRAP";
             Algorithms[NistObjectIdentifiers.IdAes128Wrap.Id] = "AESWRAP";
             Algorithms[NistObjectIdentifiers.IdAes192Wrap.Id] = "AESWRAP";
             Algorithms[NistObjectIdentifiers.IdAes256Wrap.Id] = "AESWRAP";
 
+            Algorithms["ARIAKW"] = "ARIAWRAP";
+            Algorithms[NsriObjectIdentifiers.id_aria128_kw.Id] = "ARIAWRAP";
+            Algorithms[NsriObjectIdentifiers.id_aria192_kw.Id] = "ARIAWRAP";
+            Algorithms[NsriObjectIdentifiers.id_aria256_kw.Id] = "ARIAWRAP";
+
             Algorithms[NttObjectIdentifiers.IdCamellia128Wrap.Id] = "CAMELLIAWRAP";
             Algorithms[NttObjectIdentifiers.IdCamellia192Wrap.Id] = "CAMELLIAWRAP";
             Algorithms[NttObjectIdentifiers.IdCamellia256Wrap.Id] = "CAMELLIAWRAP";
 
-            Algorithms[PkcsObjectIdentifiers.IdAlgCms3DesWrap.Id] = "DESEDEWRAP";
+            Algorithms["DESEDERFC3217WRAP"] = "DESEDEWRAP";
             Algorithms["TDEAWRAP"] = "DESEDEWRAP";
+            Algorithms[PkcsObjectIdentifiers.IdAlgCms3DesWrap.Id] = "DESEDEWRAP";
 
             Algorithms[PkcsObjectIdentifiers.IdAlgCmsRC2Wrap.Id] = "RC2WRAP";
 
+            Algorithms["SEEDKW"] = "SEEDWRAP";
             Algorithms[KisaObjectIdentifiers.IdNpkiAppCmsSeedWrap.Id] = "SEEDWRAP";
         }
 
@@ -60,14 +81,28 @@ namespace Org.BouncyCastle.Security
 
                 switch (wrapAlgorithm)
                 {
-                case WrapAlgorithm.AESWRAP:				return new AesWrapEngine();
-                case WrapAlgorithm.CAMELLIAWRAP:		return new CamelliaWrapEngine();
-                case WrapAlgorithm.DESEDEWRAP:			return new DesEdeWrapEngine();
-                case WrapAlgorithm.RC2WRAP:				return new RC2WrapEngine();
-                case WrapAlgorithm.SEEDWRAP:			return new SeedWrapEngine();
-                case WrapAlgorithm.DESEDERFC3211WRAP:	return new Rfc3211WrapEngine(new DesEdeEngine());
-                case WrapAlgorithm.AESRFC3211WRAP:		return new Rfc3211WrapEngine(AesUtilities.CreateEngine());
-                case WrapAlgorithm.CAMELLIARFC3211WRAP:	return new Rfc3211WrapEngine(new CamelliaEngine());
+                case WrapAlgorithm.AESRFC3211WRAP:
+                    return new Rfc3211WrapEngine(AesUtilities.CreateEngine());
+                case WrapAlgorithm.AESWRAP:
+                    return new AesWrapEngine();
+                case WrapAlgorithm.ARIARFC3211WRAP:
+                    return new Rfc3211WrapEngine(new AriaEngine());
+                case WrapAlgorithm.ARIAWRAP:
+                    return new AriaWrapEngine();
+                case WrapAlgorithm.CAMELLIARFC3211WRAP:
+                    return new Rfc3211WrapEngine(new CamelliaEngine());
+                case WrapAlgorithm.CAMELLIAWRAP:
+                    return new CamelliaWrapEngine();
+                case WrapAlgorithm.DESRFC3211WRAP:
+                    return new Rfc3211WrapEngine(new DesEngine());
+                case WrapAlgorithm.DESEDERFC3211WRAP:
+                    return new Rfc3211WrapEngine(new DesEdeEngine());
+                case WrapAlgorithm.DESEDEWRAP:
+                    return new DesEdeWrapEngine();
+                case WrapAlgorithm.RC2WRAP:
+                    return new RC2WrapEngine();
+                case WrapAlgorithm.SEEDWRAP:
+                    return new SeedWrapEngine();
                 }
             }
             catch (ArgumentException)