BouncyCastle update.

git-svn-id: svn://svn.code.sf.net/p/itextsharp/code/trunk@49 820d3149-562b-4f88-9aa4-a8e61a3485cf
master
psoares33 2009-07-06 21:26:39 +00:00
parent a7df15bacd
commit 8438ab26f5
9 changed files with 1319 additions and 1266 deletions

View File

@ -1,7 +1,7 @@
<VisualStudioProject>
<CSHARP
ProjectType = "Local"
ProductVersion = "7.10.6030"
ProductVersion = "7.10.3077"
SchemaVersion = "2.0"
ProjectGuid = "{84C4FDD9-3ED7-453B-B9DA-B3ED52CB071C}"
>
@ -6181,6 +6181,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "srcbc\openssl\PEMException.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "srcbc\openssl\PEMReader.cs"
SubType = "Code"

View File

@ -1141,7 +1141,7 @@ namespace Org.BouncyCastle.Crypto.Tls
}
/**
* Terminate this connection whith an alert.
* Terminate this connection with an alert.
* <p/>
* Can be used for normal closure too.
*

View File

@ -0,0 +1,22 @@
using System;
using System.IO;
namespace Org.BouncyCastle.OpenSsl
{
public class PemException
: IOException
{
public PemException(
string message)
: base(message)
{
}
public PemException(
string message,
Exception exception)
: base(message, exception)
{
}
}
}

View File

@ -213,7 +213,7 @@ namespace Org.BouncyCastle.OpenSsl
}
catch (Exception e)
{
throw new IOException("problem parsing cert: " + e.ToString());
throw new PemException("problem parsing cert: " + e.ToString());
}
}
@ -234,7 +234,7 @@ namespace Org.BouncyCastle.OpenSsl
}
catch (Exception e)
{
throw new IOException("problem parsing cert: " + e.ToString());
throw new PemException("problem parsing cert: " + e.ToString());
}
}
@ -255,7 +255,7 @@ namespace Org.BouncyCastle.OpenSsl
}
catch (Exception e)
{
throw new IOException("problem parsing cert: " + e.ToString());
throw new PemException("problem parsing cert: " + e.ToString());
}
}
@ -293,7 +293,7 @@ namespace Org.BouncyCastle.OpenSsl
}
catch (Exception e)
{
throw new IOException("problem parsing PKCS7 object: " + e.ToString());
throw new PemException("problem parsing PKCS7 object: " + e.ToString());
}
}
@ -377,7 +377,7 @@ namespace Org.BouncyCastle.OpenSsl
}
catch (Exception e)
{
throw new IOException(
throw new PemException(
"problem creating " + type + " private key: " + e.ToString());
}
}
@ -446,7 +446,7 @@ namespace Org.BouncyCastle.OpenSsl
}
catch (Exception e)
{
throw new IOException("problem parsing EC private key.", e);
throw new PemException("problem parsing EC private key.", e);
}
}
}

View File

@ -135,6 +135,8 @@ namespace Org.BouncyCastle.Security
algorithms[NttObjectIdentifiers.IdCamellia256Cbc.Id] = "CAMELLIA/CBC/PKCS7PADDING";
algorithms[KisaObjectIdentifiers.IdSeedCbc.Id] = "SEED/CBC/PKCS7PADDING";
algorithms["1.3.6.1.4.1.3029.1.2"] = "BLOWFISH/CBC";
}
private CipherUtilities()

View File

@ -51,7 +51,8 @@ namespace Org.BouncyCastle.Security
NistObjectIdentifiers.IdAes256Ecb,
NistObjectIdentifiers.IdAes256Ofb,
NistObjectIdentifiers.IdAes256Wrap);
AddKgAlgorithm("BLOWFISH");
AddKgAlgorithm("BLOWFISH",
"1.3.6.1.4.1.3029.1.2");
AddKgAlgorithm("CAMELLIA",
"CAMELLIAWRAP");
AddKgAlgorithm("CAMELLIA128",
@ -225,94 +226,21 @@ namespace Org.BouncyCastle.Security
if (canonicalName == null)
throw new SecurityUtilityException("KeyGenerator " + algorithm + " not recognised.");
int defaultKeySize = FindDefaultKeySize(canonicalName);
if (defaultKeySize == -1)
throw new SecurityUtilityException("KeyGenerator " + algorithm
+ " (" + canonicalName + ") not supported.");
switch (canonicalName)
{
case "DES":
return new DesKeyGenerator(64);
return new DesKeyGenerator(defaultKeySize);
case "DESEDE":
return new DesEdeKeyGenerator(128);
case "DESEDE3":
return new DesEdeKeyGenerator(192);
case "AES":
return new CipherKeyGenerator(192);
case "AES128":
return new CipherKeyGenerator(128);
case "AES192":
return new CipherKeyGenerator(192);
case "AES256":
return new CipherKeyGenerator(256);
case "BLOWFISH":
return new CipherKeyGenerator(448);
case "CAMELLIA":
return new CipherKeyGenerator(256);
case "CAMELLIA128":
return new CipherKeyGenerator(128);
case "CAMELLIA192":
return new CipherKeyGenerator(192);
case "CAMELLIA256":
return new CipherKeyGenerator(256);
case "CAST5":
return new CipherKeyGenerator(128);
case "CAST6":
return new CipherKeyGenerator(256);
case "GOST28147":
return new CipherKeyGenerator(256);
case "HC128":
return new CipherKeyGenerator(128);
case "HC256":
return new CipherKeyGenerator(256);
case "HMACMD2":
case "HMACMD4":
case "HMACMD5":
return new CipherKeyGenerator(128);
case "HMACSHA1":
return new CipherKeyGenerator(160);
case "HMACSHA224":
return new CipherKeyGenerator(224);
case "HMACSHA256":
return new CipherKeyGenerator(256);
case "HMACSHA384":
return new CipherKeyGenerator(384);
case "HMACSHA512":
return new CipherKeyGenerator(512);
case "HMACRIPEMD128":
return new CipherKeyGenerator(128);
case "HMACRIPEMD160":
return new CipherKeyGenerator(160);
case "HMACTIGER":
return new CipherKeyGenerator(192);
case "IDEA":
return new CipherKeyGenerator(128);
case "NOEKEON":
return new CipherKeyGenerator(128);
case "RC2":
case "RC4":
case "RC5":
return new CipherKeyGenerator(128);
case "RC5-64":
case "RC6":
return new CipherKeyGenerator(256);
case "RIJNDAEL":
return new CipherKeyGenerator(192);
case "SALSA20":
return new CipherKeyGenerator(128);
case "SEED":
return new CipherKeyGenerator(128);
case "SERPENT":
return new CipherKeyGenerator(192);
case "SKIPJACK":
return new CipherKeyGenerator(80);
case "TEA":
case "XTEA":
return new CipherKeyGenerator(128);
case "TWOFISH":
return new CipherKeyGenerator(256);
case "VMPC":
case "VMPC-KSA3":
return new CipherKeyGenerator(128);
return new DesEdeKeyGenerator(defaultKeySize);
default:
return new CipherKeyGenerator(defaultKeySize);
}
throw new SecurityUtilityException("KeyGenerator " + algorithm + " not recognised.");
}
public static IAsymmetricCipherKeyPairGenerator GetKeyPairGenerator(
@ -351,7 +279,94 @@ namespace Org.BouncyCastle.Security
break;
}
throw new SecurityUtilityException("KeyPairGenerator " + algorithm + " not recognised.");
throw new SecurityUtilityException("KeyPairGenerator " + algorithm
+ " (" + canonicalName + ") not supported.");
}
internal static int GetDefaultKeySize(
DerObjectIdentifier oid)
{
return GetDefaultKeySize(oid.Id);
}
internal static int GetDefaultKeySize(
string algorithm)
{
string canonicalName = GetCanonicalKeyGeneratorAlgorithm(algorithm);
if (canonicalName == null)
throw new SecurityUtilityException("KeyGenerator " + algorithm + " not recognised.");
int defaultKeySize = FindDefaultKeySize(canonicalName);
if (defaultKeySize == -1)
throw new SecurityUtilityException("KeyGenerator " + algorithm
+ " (" + canonicalName + ") not supported.");
return defaultKeySize;
}
private static int FindDefaultKeySize(
string canonicalName)
{
switch (canonicalName)
{
case "DES":
return 64;
case "BLOWFISH":
case "SKIPJACK":
return 80;
case "AES128":
case "CAMELLIA128":
case "CAST5":
case "DESEDE":
case "HC128":
case "HMACMD2":
case "HMACMD4":
case "HMACMD5":
case "HMACRIPEMD128":
case "IDEA":
case "NOEKEON":
case "RC2":
case "RC4":
case "RC5":
case "SALSA20":
case "SEED":
case "TEA":
case "XTEA":
case "VMPC":
case "VMPC-KSA3":
return 128;
case "HMACRIPEMD160":
case "HMACSHA1":
return 160;
case "AES":
case "AES192":
case "CAMELLIA192":
case "DESEDE3":
case "HMACTIGER":
case "RIJNDAEL":
case "SERPENT":
return 192;
case "HMACSHA224":
return 224;
case "AES256":
case "CAMELLIA":
case "CAMELLIA256":
case "CAST6":
case "GOST28147":
case "HC256":
case "HMACSHA256":
case "RC5-64":
case "RC6":
case "TWOFISH":
return 256;
case "HMACSHA384":
return 384;
case "HMACSHA512":
return 512;
default:
return -1;
}
}
}
}

View File

@ -48,7 +48,8 @@ namespace Org.BouncyCastle.Security
NistObjectIdentifiers.IdAes256Ecb,
NistObjectIdentifiers.IdAes256Ofb,
NistObjectIdentifiers.IdAes256Wrap);
AddAlgorithm("BLOWFISH");
AddAlgorithm("BLOWFISH",
"1.3.6.1.4.1.3029.1.2");
AddAlgorithm("CAMELLIA",
"CAMELLIAWRAP");
AddAlgorithm("CAMELLIA128",
@ -269,7 +270,6 @@ namespace Org.BouncyCastle.Security
{
// TODO These algorithms support an IV (see GetCipherParameters)
// but JCE doesn't seem to provide an AlgorithmParametersGenerator for them
// case "BLOWFISH":
// case "RIJNDAEL":
// case "SKIPJACK":
// case "TWOFISH":
@ -279,6 +279,8 @@ namespace Org.BouncyCastle.Security
case "AES192":
case "AES256":
return CreateIVOctetString(random, 16);
case "BLOWFISH":
return CreateIVOctetString(random, 8);
case "CAMELLIA":
case "CAMELLIA128":
case "CAMELLIA192":

View File

@ -47,7 +47,11 @@ namespace Org.BouncyCastle.Security
AlgorithmIdentifier algID = keyInfo.AlgorithmID;
DerObjectIdentifier algOid = algID.ObjectID;
if (algOid.Equals(PkcsObjectIdentifiers.RsaEncryption))
// TODO See RSAUtil.isRsaOid in Java build
if (algOid.Equals(PkcsObjectIdentifiers.RsaEncryption)
|| algOid.Equals(X509ObjectIdentifiers.IdEARsa)
|| algOid.Equals(PkcsObjectIdentifiers.IdRsassaPss)
|| algOid.Equals(PkcsObjectIdentifiers.IdRsaesOaep))
{
RsaPrivateKeyStructure keyStructure = new RsaPrivateKeyStructure(
Asn1Sequence.GetInstance(keyInfo.PrivateKey));

View File

@ -47,8 +47,11 @@ namespace Org.BouncyCastle.Security
AlgorithmIdentifier algID = keyInfo.AlgorithmID;
DerObjectIdentifier algOid = algID.ObjectID;
// TODO See RSAUtil.isRsaOid in Java build
if (algOid.Equals(PkcsObjectIdentifiers.RsaEncryption)
|| algOid.Equals(X509ObjectIdentifiers.IdEARsa))
|| algOid.Equals(X509ObjectIdentifiers.IdEARsa)
|| algOid.Equals(PkcsObjectIdentifiers.IdRsassaPss)
|| algOid.Equals(PkcsObjectIdentifiers.IdRsaesOaep))
{
RsaPublicKeyStructure pubKey = RsaPublicKeyStructure.GetInstance(
keyInfo.GetPublicKey());