summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Hook <dgh@bouncycastle.org>2019-01-19 15:55:06 +1100
committerDavid Hook <dgh@bouncycastle.org>2019-01-19 15:55:06 +1100
commite00d3aee5f24da1827897c771e4a83c9d473b679 (patch)
treeac60032fe08e4a9c83116828798b3e46e7414c79
parentfixed KeyTransRecipientInfoGenerator to invoke overridable method for wrappin... (diff)
downloadBouncyCastle.NET-ed25519-e00d3aee5f24da1827897c771e4a83c9d473b679.tar.xz
added initialisation to Asn1KeyWrapper
-rw-r--r--crypto/src/crypto/operators/Asn1KeyWrapper.cs43
1 files changed, 21 insertions, 22 deletions
diff --git a/crypto/src/crypto/operators/Asn1KeyWrapper.cs b/crypto/src/crypto/operators/Asn1KeyWrapper.cs
index 6e608b94b..527e3df31 100644
--- a/crypto/src/crypto/operators/Asn1KeyWrapper.cs
+++ b/crypto/src/crypto/operators/Asn1KeyWrapper.cs
@@ -17,15 +17,13 @@ namespace Org.BouncyCastle.Crypto.Operators
 {
     public class Asn1KeyWrapper : IKeyWrapper
     {
-        private X509Certificate cert;
         private string algorithm;
         private IKeyWrapper wrapper;
 
         public Asn1KeyWrapper(string algorithm, X509Certificate cert)
         {
             this.algorithm = algorithm;
-            this.cert = cert;
-            wrapper = KeyWrapperUtil.WrapperForName(algorithm);
+            wrapper = KeyWrapperUtil.WrapperForName(algorithm, cert.GetPublicKey());
         }
 
         public object AlgorithmDetails
@@ -55,7 +53,7 @@ namespace Org.BouncyCastle.Crypto.Operators
             providerMap["RSA/NONE/OAEPWITHSHA512ANDMGF1PADDING"] = new WrapperCreator(RsaOaepWrapper.Rsa_Sha512_Oaep);
         }
 
-        public static IKeyWrapper WrapperForName(string algorithm)
+        public static IKeyWrapper WrapperForName(string algorithm, ICipherParameters parameters)
         {
             WrapperProvider provider = (WrapperProvider)providerMap[Strings.ToUpperCase(algorithm)];
 
@@ -64,10 +62,10 @@ namespace Org.BouncyCastle.Crypto.Operators
                 throw new ArgumentException("could not resolve " + algorithm + " to a KeyWrapper");
             }
 
-            return (IKeyWrapper)provider.createWrapper();
+            return (IKeyWrapper)provider.createWrapper(true, parameters);
         }
 
-        public static IKeyUnwrapper UnwrapperForName(string algorithm)
+        public static IKeyUnwrapper UnwrapperForName(string algorithm, ICipherParameters parameters)
         {
             WrapperProvider provider = (WrapperProvider)providerMap[Strings.ToUpperCase(algorithm)];
             if (provider == null)
@@ -75,11 +73,11 @@ namespace Org.BouncyCastle.Crypto.Operators
                 throw new ArgumentException("could not resolve " + algorithm + " to a KeyUnwrapper");
             }
 
-            return (IKeyUnwrapper)provider.createWrapper();
+            return (IKeyUnwrapper)provider.createWrapper(false, parameters);
         }
     }
 
-    internal delegate object WrapperCreatorDelegate();
+    internal delegate object WrapperCreatorDelegate(bool forWrapping, ICipherParameters parameters);
 
     /// <summary>
     /// Wraps delegate and implements the WrapperProvider Interface.
@@ -93,48 +91,48 @@ namespace Org.BouncyCastle.Crypto.Operators
             this.creator = creator;
         }
 
-        public object createWrapper()
+        public object createWrapper(bool forWrapping, ICipherParameters parameters)
         {
-            return this.creator.Invoke();
+            return this.creator.Invoke(forWrapping, parameters);
         }
     }
 
     internal interface WrapperProvider
     {
-        object createWrapper();
+        object createWrapper(bool forWrapping, ICipherParameters parameters);
     }
 
     internal class RsaOaepWrapper : IKeyWrapper, IKeyUnwrapper
     {
-        internal static object Rsa_Sha1_Oaep()
+        internal static object Rsa_Sha1_Oaep(bool forWrapping, ICipherParameters parameters)
         {
-            return new RsaOaepWrapper(OiwObjectIdentifiers.IdSha1, new Sha1Digest());
+            return new RsaOaepWrapper(forWrapping, parameters, OiwObjectIdentifiers.IdSha1, new Sha1Digest());
         }
 
-        internal static object Rsa_Sha224_Oaep()
+        internal static object Rsa_Sha224_Oaep(bool forWrapping, ICipherParameters parameters)
         {
-            return new RsaOaepWrapper(NistObjectIdentifiers.IdSha224, new Sha224Digest());
+            return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha224, new Sha224Digest());
         }
 
-        internal static object Rsa_Sha256_Oaep()
+        internal static object Rsa_Sha256_Oaep(bool forWrapping, ICipherParameters parameters)
         {
-            return new RsaOaepWrapper(NistObjectIdentifiers.IdSha256, new Sha256Digest());
+            return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha256, new Sha256Digest());
         }
 
-        internal static object Rsa_Sha384_Oaep()
+        internal static object Rsa_Sha384_Oaep(bool forWrapping, ICipherParameters parameters)
         {
-            return new RsaOaepWrapper(NistObjectIdentifiers.IdSha384, new Sha384Digest());
+            return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha384, new Sha384Digest());
         }
 
-        internal static object Rsa_Sha512_Oaep()
+        internal static object Rsa_Sha512_Oaep(bool forWrapping, ICipherParameters parameters)
         {
-            return new RsaOaepWrapper(NistObjectIdentifiers.IdSha512, new Sha512Digest());
+            return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha512, new Sha512Digest());
         }
 
         private readonly AlgorithmIdentifier algId;
         private readonly IAsymmetricBlockCipher engine;
 
-        public RsaOaepWrapper(DerObjectIdentifier digestOid, IDigest digest)
+        public RsaOaepWrapper(bool forWrapping, ICipherParameters parameters, DerObjectIdentifier digestOid, IDigest digest)
         {
             AlgorithmIdentifier digestAlgId = new AlgorithmIdentifier(digestOid, DerNull.Instance);
 
@@ -145,6 +143,7 @@ namespace Org.BouncyCastle.Crypto.Operators
                     new AlgorithmIdentifier(PkcsObjectIdentifiers.IdMgf1, digestAlgId),
                     RsaesOaepParameters.DefaultPSourceAlgorithm));
             this.engine = new OaepEncoding(new RsaBlindedEngine());
+            this.engine.Init(forWrapping, parameters);
         }
 
         public object AlgorithmDetails