diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-07-17 18:55:46 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-07-17 18:55:46 +0700 |
commit | 67108e3c641758ebe98484cf52454471d9948e0d (patch) | |
tree | a9437e154bf3b71ed41591f94fbe65fa04891bed /crypto/src | |
parent | Remove unused digest (diff) | |
download | BouncyCastle.NET-ed25519-67108e3c641758ebe98484cf52454471d9948e0d.tar.xz |
Utility method for selecting AES engine
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/cms/EnvelopedDataHelper.cs | 9 | ||||
-rw-r--r-- | crypto/src/crypto/AesUtilities.cs | 12 | ||||
-rw-r--r-- | crypto/src/crypto/engines/AesWrapEngine.cs | 2 | ||||
-rw-r--r-- | crypto/src/crypto/fpe/FpeFf1Engine.cs | 3 | ||||
-rw-r--r-- | crypto/src/crypto/fpe/FpeFf3_1Engine.cs | 2 | ||||
-rw-r--r-- | crypto/src/crypto/modes/GcmSivBlockCipher.cs | 2 | ||||
-rw-r--r-- | crypto/src/crypto/util/CipherFactory.cs | 2 | ||||
-rw-r--r-- | crypto/src/security/CipherUtilities.cs | 6 | ||||
-rw-r--r-- | crypto/src/security/MacUtilities.cs | 2 | ||||
-rw-r--r-- | crypto/src/security/WrapperUtilities.cs | 2 | ||||
-rw-r--r-- | crypto/src/tls/crypto/impl/bc/BcTlsCrypto.cs | 2 |
11 files changed, 25 insertions, 19 deletions
diff --git a/crypto/src/cms/EnvelopedDataHelper.cs b/crypto/src/cms/EnvelopedDataHelper.cs index 8c4dd7bf9..616048297 100644 --- a/crypto/src/cms/EnvelopedDataHelper.cs +++ b/crypto/src/cms/EnvelopedDataHelper.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; - + using Org.BouncyCastle.Asn1; -using Org.BouncyCastle.Asn1.Nist; -using Org.BouncyCastle.Asn1.Pkcs; using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Crypto.Utilities; using Org.BouncyCastle.Security; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Cms { @@ -55,7 +50,7 @@ namespace Org.BouncyCastle.Cms // || NistObjectIdentifiers.IdAes192Cbc.Equals(algorithm) // || NistObjectIdentifiers.IdAes256Cbc.Equals(algorithm)) // { - // return new Rfc3211WrapEngine(new AesEngine()); + // return new Rfc3211WrapEngine(AesUtilities.CreateEngine()); // } // else if (PkcsObjectIdentifiers.DesEde3Cbc.Equals(algorithm)) // { diff --git a/crypto/src/crypto/AesUtilities.cs b/crypto/src/crypto/AesUtilities.cs new file mode 100644 index 000000000..648f988bc --- /dev/null +++ b/crypto/src/crypto/AesUtilities.cs @@ -0,0 +1,12 @@ +using Org.BouncyCastle.Crypto.Engines; + +namespace Org.BouncyCastle.Crypto +{ + public static class AesUtilities + { + public static IBlockCipher CreateEngine() + { + return new AesEngine(); + } + } +} diff --git a/crypto/src/crypto/engines/AesWrapEngine.cs b/crypto/src/crypto/engines/AesWrapEngine.cs index 1ce01542b..bf9e724cd 100644 --- a/crypto/src/crypto/engines/AesWrapEngine.cs +++ b/crypto/src/crypto/engines/AesWrapEngine.cs @@ -9,7 +9,7 @@ namespace Org.BouncyCastle.Crypto.Engines : Rfc3394WrapEngine { public AesWrapEngine() - : base(new AesEngine()) + : base(AesUtilities.CreateEngine()) { } } diff --git a/crypto/src/crypto/fpe/FpeFf1Engine.cs b/crypto/src/crypto/fpe/FpeFf1Engine.cs index acd31b6f4..e2d72c824 100644 --- a/crypto/src/crypto/fpe/FpeFf1Engine.cs +++ b/crypto/src/crypto/fpe/FpeFf1Engine.cs @@ -1,6 +1,5 @@ using System; -using Org.BouncyCastle.Crypto.Engines; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Crypto.Utilities; @@ -10,7 +9,7 @@ namespace Org.BouncyCastle.Crypto.Fpe : FpeEngine { public FpeFf1Engine() - : this(new AesEngine()) + : this(AesUtilities.CreateEngine()) { } diff --git a/crypto/src/crypto/fpe/FpeFf3_1Engine.cs b/crypto/src/crypto/fpe/FpeFf3_1Engine.cs index aa238e46a..71203aecf 100644 --- a/crypto/src/crypto/fpe/FpeFf3_1Engine.cs +++ b/crypto/src/crypto/fpe/FpeFf3_1Engine.cs @@ -11,7 +11,7 @@ namespace Org.BouncyCastle.Crypto.Fpe : FpeEngine { public FpeFf3_1Engine() - : this(new AesEngine()) + : this(AesUtilities.CreateEngine()) { } diff --git a/crypto/src/crypto/modes/GcmSivBlockCipher.cs b/crypto/src/crypto/modes/GcmSivBlockCipher.cs index eb070bf0c..5af3429f2 100644 --- a/crypto/src/crypto/modes/GcmSivBlockCipher.cs +++ b/crypto/src/crypto/modes/GcmSivBlockCipher.cs @@ -123,7 +123,7 @@ namespace Org.BouncyCastle.Crypto.Modes * Constructor. */ public GcmSivBlockCipher() - : this(new AesEngine()) + : this(AesUtilities.CreateEngine()) { } diff --git a/crypto/src/crypto/util/CipherFactory.cs b/crypto/src/crypto/util/CipherFactory.cs index f5998267d..2e8c44bb4 100644 --- a/crypto/src/crypto/util/CipherFactory.cs +++ b/crypto/src/crypto/util/CipherFactory.cs @@ -116,7 +116,7 @@ namespace Org.BouncyCastle.Crypto.Utilities || NistObjectIdentifiers.IdAes192Cbc.Equals(algorithm) || NistObjectIdentifiers.IdAes256Cbc.Equals(algorithm)) { - cipher = new CbcBlockCipher(new AesEngine()); + cipher = new CbcBlockCipher(AesUtilities.CreateEngine()); } else if (PkcsObjectIdentifiers.DesEde3Cbc.Equals(algorithm)) { diff --git a/crypto/src/security/CipherUtilities.cs b/crypto/src/security/CipherUtilities.cs index a6849c102..8ed5d8d41 100644 --- a/crypto/src/security/CipherUtilities.cs +++ b/crypto/src/security/CipherUtilities.cs @@ -339,7 +339,7 @@ namespace Org.BouncyCastle.Security "PBEWITHMD5AND256BITAES-CBC-OPENSSL")) { return new PaddedBufferedBlockCipher( - new CbcBlockCipher(new AesEngine())); + new CbcBlockCipher(AesUtilities.CreateEngine())); } } } @@ -368,7 +368,7 @@ namespace Org.BouncyCastle.Security switch (cipherAlgorithm) { case CipherAlgorithm.AES: - blockCipher = new AesEngine(); + blockCipher = AesUtilities.CreateEngine(); break; case CipherAlgorithm.ARC4: streamCipher = new RC4Engine(); @@ -759,7 +759,7 @@ namespace Org.BouncyCastle.Security { switch (cipherAlgorithm) { - case CipherAlgorithm.AES: return new AesEngine(); + case CipherAlgorithm.AES: return AesUtilities.CreateEngine(); case CipherAlgorithm.ARIA: return new AriaEngine(); case CipherAlgorithm.BLOWFISH: return new BlowfishEngine(); case CipherAlgorithm.CAMELLIA: return new CamelliaEngine(); diff --git a/crypto/src/security/MacUtilities.cs b/crypto/src/security/MacUtilities.cs index f9f586d29..9490616be 100644 --- a/crypto/src/security/MacUtilities.cs +++ b/crypto/src/security/MacUtilities.cs @@ -115,7 +115,7 @@ namespace Org.BouncyCastle.Security if (mechanism == "AESCMAC") { - return new CMac(new AesEngine()); + return new CMac(AesUtilities.CreateEngine()); } if (mechanism == "DESMAC") { diff --git a/crypto/src/security/WrapperUtilities.cs b/crypto/src/security/WrapperUtilities.cs index 983ff824c..48ffe3a96 100644 --- a/crypto/src/security/WrapperUtilities.cs +++ b/crypto/src/security/WrapperUtilities.cs @@ -67,7 +67,7 @@ namespace Org.BouncyCastle.Security 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(new AesEngine()); + case WrapAlgorithm.AESRFC3211WRAP: return new Rfc3211WrapEngine(AesUtilities.CreateEngine()); case WrapAlgorithm.CAMELLIARFC3211WRAP: return new Rfc3211WrapEngine(new CamelliaEngine()); } } diff --git a/crypto/src/tls/crypto/impl/bc/BcTlsCrypto.cs b/crypto/src/tls/crypto/impl/bc/BcTlsCrypto.cs index d6a41b86d..0375950c3 100644 --- a/crypto/src/tls/crypto/impl/bc/BcTlsCrypto.cs +++ b/crypto/src/tls/crypto/impl/bc/BcTlsCrypto.cs @@ -568,7 +568,7 @@ namespace Org.BouncyCastle.Tls.Crypto.Impl.BC protected virtual IBlockCipher CreateAesEngine() { - return new AesEngine(); + return AesUtilities.CreateEngine(); } protected virtual IBlockCipher CreateAriaEngine() |