diff options
author | Carlos Alberto Costa Beppler <beppler@gmail.com> | 2015-03-24 10:16:11 -0300 |
---|---|---|
committer | Carlos Alberto Costa Beppler <beppler@gmail.com> | 2015-03-24 10:16:11 -0300 |
commit | a6da1221e74d909840ca47be3798f3942f40ebb3 (patch) | |
tree | 9f614249a41687b82b02afa2da9cc63243c9a712 /crypto/src | |
parent | Update TLS for draft-ietf-tls-session-hash-04 (diff) | |
download | BouncyCastle.NET-ed25519-a6da1221e74d909840ca47be3798f3942f40ebb3.tar.xz |
Correct duplicate key exception when more than one signer use the same digest algorithm.
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/cms/CMSSignedDataGenerator.cs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/crypto/src/cms/CMSSignedDataGenerator.cs b/crypto/src/cms/CMSSignedDataGenerator.cs index f31105c41..1659a4117 100644 --- a/crypto/src/cms/CMSSignedDataGenerator.cs +++ b/crypto/src/cms/CMSSignedDataGenerator.cs @@ -93,19 +93,24 @@ namespace Org.BouncyCastle.Cms { AlgorithmIdentifier digAlgId = DigestAlgorithmID; string digestName = Helper.GetDigestAlgName(digestOID); - IDigest dig = Helper.GetDigestInstance(digestName); string signatureName = digestName + "with" + Helper.GetEncryptionAlgName(encOID); ISigner sig = Helper.GetSignatureInstance(signatureName); - // TODO Optimise the case where more than one signer with same digest - if (content != null) - { - content.Write(new DigOutputStream(dig)); - } + byte[] hash; - byte[] hash = DigestUtilities.DoFinal(dig); - outer._digests.Add(digestOID, hash.Clone()); + if (outer._digests.Contains(digestOID)) + hash = (byte[])outer._digests[digestOID]; + else + { + IDigest dig = Helper.GetDigestInstance(digestName); + if (content != null) + { + content.Write(new DigOutputStream(dig)); + } + hash = DigestUtilities.DoFinal(dig); + outer._digests.Add(digestOID, hash.Clone()); + } sig.Init(true, new ParametersWithRandom(key, random)); #if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT |