diff --git a/crypto/src/security/CipherUtilities.cs b/crypto/src/security/CipherUtilities.cs
index cda769535..cdb711f69 100644
--- a/crypto/src/security/CipherUtilities.cs
+++ b/crypto/src/security/CipherUtilities.cs
@@ -389,11 +389,9 @@ namespace Org.BouncyCastle.Security
case CipherAlgorithm.HC256:
streamCipher = new HC256Engine();
break;
-#if INCLUDE_IDEA
case CipherAlgorithm.IDEA:
blockCipher = new IdeaEngine();
break;
-#endif
case CipherAlgorithm.NOEKEON:
blockCipher = new NoekeonEngine();
break;
@@ -716,9 +714,7 @@ namespace Org.BouncyCastle.Security
case CipherAlgorithm.DES: return new DesEngine();
case CipherAlgorithm.DESEDE: return new DesEdeEngine();
case CipherAlgorithm.GOST28147: return new Gost28147Engine();
-#if INCLUDE_IDEA
case CipherAlgorithm.IDEA: return new IdeaEngine();
-#endif
case CipherAlgorithm.NOEKEON: return new NoekeonEngine();
case CipherAlgorithm.RC2: return new RC2Engine();
case CipherAlgorithm.RC5: return new RC532Engine();
diff --git a/crypto/src/security/DotNetUtilities.cs b/crypto/src/security/DotNetUtilities.cs
index 036c0d519..d50e17d39 100644
--- a/crypto/src/security/DotNetUtilities.cs
+++ b/crypto/src/security/DotNetUtilities.cs
@@ -4,6 +4,7 @@ using System;
using System.Security.Cryptography;
using SystemX509 = System.Security.Cryptography.X509Certificates;
+using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
@@ -161,22 +162,21 @@ namespace Org.BouncyCastle.Security
public static RSA ToRSA(RsaKeyParameters rsaKey)
{
- RSAParameters rp = ToRSAParameters(rsaKey);
- RSACryptoServiceProvider rsaCsp = new RSACryptoServiceProvider();
- // TODO This call appears to not work for private keys (when no CRT info)
- rsaCsp.ImportParameters(rp);
- return rsaCsp;
- }
+ // TODO This appears to not work for private keys (when no CRT info)
+ return CreateRSAProvider(ToRSAParameters(rsaKey));
+ }
public static RSA ToRSA(RsaPrivateCrtKeyParameters privKey)
{
- RSAParameters rp = ToRSAParameters(privKey);
- RSACryptoServiceProvider rsaCsp = new RSACryptoServiceProvider();
- rsaCsp.ImportParameters(rp);
- return rsaCsp;
- }
+ return CreateRSAProvider(ToRSAParameters(privKey));
+ }
- public static RSAParameters ToRSAParameters(RsaKeyParameters rsaKey)
+ public static RSA ToRSA(RsaPrivateKeyStructure privKey)
+ {
+ return CreateRSAProvider(ToRSAParameters(privKey));
+ }
+
+ public static RSAParameters ToRSAParameters(RsaKeyParameters rsaKey)
{
RSAParameters rp = new RSAParameters();
rp.Modulus = rsaKey.Modulus.ToByteArrayUnsigned();
@@ -201,7 +201,21 @@ namespace Org.BouncyCastle.Security
return rp;
}
- // TODO Move functionality to more general class
+ public static RSAParameters ToRSAParameters(RsaPrivateKeyStructure privKey)
+ {
+ RSAParameters rp = new RSAParameters();
+ rp.Modulus = privKey.Modulus.ToByteArrayUnsigned();
+ rp.Exponent = privKey.PublicExponent.ToByteArrayUnsigned();
+ rp.P = privKey.Prime1.ToByteArrayUnsigned();
+ rp.Q = privKey.Prime2.ToByteArrayUnsigned();
+ rp.D = ConvertRSAParametersField(privKey.PrivateExponent, rp.Modulus.Length);
+ rp.DP = ConvertRSAParametersField(privKey.Exponent1, rp.P.Length);
+ rp.DQ = ConvertRSAParametersField(privKey.Exponent2, rp.Q.Length);
+ rp.InverseQ = ConvertRSAParametersField(privKey.Coefficient, rp.Q.Length);
+ return rp;
+ }
+
+ // TODO Move functionality to more general class
private static byte[] ConvertRSAParametersField(BigInteger n, int size)
{
byte[] bs = n.ToByteArrayUnsigned();
@@ -216,6 +230,13 @@ namespace Org.BouncyCastle.Security
Array.Copy(bs, 0, padded, size - bs.Length, bs.Length);
return padded;
}
+
+ private static RSA CreateRSAProvider(RSAParameters rp)
+ {
+ RSACryptoServiceProvider rsaCsp = new RSACryptoServiceProvider();
+ rsaCsp.ImportParameters(rp);
+ return rsaCsp;
+ }
}
}
diff --git a/crypto/src/security/MacUtilities.cs b/crypto/src/security/MacUtilities.cs
index 49162fb57..d1f8c89b4 100644
--- a/crypto/src/security/MacUtilities.cs
+++ b/crypto/src/security/MacUtilities.cs
@@ -185,7 +185,6 @@ namespace Org.BouncyCastle.Security
{
return new CfbBlockCipherMac(new SkipjackEngine());
}
-#if INCLUDE_IDEA
if (mechanism == "IDEAMAC")
{
return new CbcBlockCipherMac(new IdeaEngine());
@@ -194,7 +193,6 @@ namespace Org.BouncyCastle.Security
{
return new CfbBlockCipherMac(new IdeaEngine());
}
-#endif
if (mechanism == "RC2MAC")
{
return new CbcBlockCipherMac(new RC2Engine());
@@ -232,12 +230,17 @@ namespace Org.BouncyCastle.Security
return (string) algorithms[oid.Id];
}
- public static byte[] DoFinal(
- IMac mac)
+ public static byte[] DoFinal(IMac mac)
{
byte[] b = new byte[mac.GetMacSize()];
mac.DoFinal(b, 0);
return b;
}
+
+ public static byte[] DoFinal(IMac mac, byte[] input)
+ {
+ mac.BlockUpdate(input, 0, input.Length);
+ return DoFinal(mac);
+ }
}
}
diff --git a/crypto/src/security/ParameterUtilities.cs b/crypto/src/security/ParameterUtilities.cs
index bf448edff..b2d7c0dff 100644
--- a/crypto/src/security/ParameterUtilities.cs
+++ b/crypto/src/security/ParameterUtilities.cs
@@ -83,10 +83,8 @@ namespace Org.BouncyCastle.Security
CryptoProObjectIdentifiers.GostR28147Cbc);
AddAlgorithm("HC128");
AddAlgorithm("HC256");
-#if INCLUDE_IDEA
AddAlgorithm("IDEA",
"1.3.6.1.4.1.188.7.1.1.2");
-#endif
AddAlgorithm("NOEKEON");
AddAlgorithm("RC2",
PkcsObjectIdentifiers.RC2Cbc,
@@ -234,12 +232,10 @@ namespace Org.BouncyCastle.Security
{
iv = Cast5CbcParameters.GetInstance(asn1Params).GetIV();
}
-#if INCLUDE_IDEA
else if (canonical == "IDEA")
{
iv = IdeaCbcPar.GetInstance(asn1Params).GetIV();
}
-#endif
else if (canonical == "RC2")
{
iv = RC2CbcParameter.GetInstance(asn1Params).GetIV();
@@ -288,10 +284,8 @@ namespace Org.BouncyCastle.Security
if (canonical == "CAST5")
return new Cast5CbcParameters(CreateIV(random, 8), 128);
-#if INCLUDE_IDEA
if (canonical == "IDEA")
return new IdeaCbcPar(CreateIV(random, 8));
-#endif
if (canonical == "RC2")
return new RC2CbcParameter(CreateIV(random, 8));
|