diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-06-14 13:01:06 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-06-14 13:01:06 +0700 |
commit | ceebe8fb52daf0fbadecbfb0e0a86b48ce011b38 (patch) | |
tree | b9084b3b32bea4462f775211adb3c666030a8c32 /crypto/src/cms/KeyAgreeRecipientInformation.cs | |
parent | Prefer AES/GCM over CHACHA20_POLY1305 (cipher suites) (diff) | |
download | BouncyCastle.NET-ed25519-ceebe8fb52daf0fbadecbfb0e0a86b48ce011b38.tar.xz |
Add new variant of GetBasicAgreementWithKdf
Diffstat (limited to 'crypto/src/cms/KeyAgreeRecipientInformation.cs')
-rw-r--r-- | crypto/src/cms/KeyAgreeRecipientInformation.cs | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/crypto/src/cms/KeyAgreeRecipientInformation.cs b/crypto/src/cms/KeyAgreeRecipientInformation.cs index 398082810..cc1823cc6 100644 --- a/crypto/src/cms/KeyAgreeRecipientInformation.cs +++ b/crypto/src/cms/KeyAgreeRecipientInformation.cs @@ -123,10 +123,8 @@ namespace Org.BouncyCastle.Cms throw new CmsException("No support for 'originator' as IssuerAndSerialNumber or SubjectKeyIdentifier"); } - private KeyParameter CalculateAgreedWrapKey( - string wrapAlg, - AsymmetricKeyParameter senderPublicKey, - AsymmetricKeyParameter receiverPrivateKey) + private KeyParameter CalculateAgreedWrapKey(DerObjectIdentifier wrapAlgOid, + AsymmetricKeyParameter senderPublicKey, AsymmetricKeyParameter receiverPrivateKey) { DerObjectIdentifier agreeAlgID = keyEncAlg.Algorithm; @@ -150,23 +148,20 @@ namespace Org.BouncyCastle.Cms (ECPrivateKeyParameters)receiverPrivateParams); } - IBasicAgreement agreement = AgreementUtilities.GetBasicAgreementWithKdf( - agreeAlgID, wrapAlg); + IBasicAgreement agreement = AgreementUtilities.GetBasicAgreementWithKdf(agreeAlgID, wrapAlgOid); agreement.Init(receiverPrivateParams); BigInteger agreedValue = agreement.CalculateAgreement(senderPublicParams); - int wrapKeySize = GeneratorUtilities.GetDefaultKeySize(wrapAlg) / 8; + int wrapKeySize = GeneratorUtilities.GetDefaultKeySize(wrapAlgOid) / 8; byte[] wrapKeyBytes = X9IntegerConverter.IntegerToBytes(agreedValue, wrapKeySize); - return ParameterUtilities.CreateKeyParameter(wrapAlg, wrapKeyBytes); + return ParameterUtilities.CreateKeyParameter(wrapAlgOid, wrapKeyBytes); } - private KeyParameter UnwrapSessionKey( - string wrapAlg, - KeyParameter agreedKey) + private KeyParameter UnwrapSessionKey(DerObjectIdentifier wrapAlgOid, KeyParameter agreedKey) { byte[] encKeyOctets = encryptedKey.GetOctets(); - IWrapper keyCipher = WrapperUtilities.GetWrapper(wrapAlg); + IWrapper keyCipher = WrapperUtilities.GetWrapper(wrapAlgOid); keyCipher.Init(false, agreedKey); byte[] sKeyBytes = keyCipher.Unwrap(encKeyOctets, 0, encKeyOctets.Length); return ParameterUtilities.CreateKeyParameter(GetContentAlgorithmName(), sKeyBytes); @@ -177,16 +172,14 @@ namespace Org.BouncyCastle.Cms { try { - string wrapAlg = DerObjectIdentifier.GetInstance( - Asn1Sequence.GetInstance(keyEncAlg.Parameters)[0]).Id; + var wrapAlgOid = DerObjectIdentifier.GetInstance(Asn1Sequence.GetInstance(keyEncAlg.Parameters)[0]); AsymmetricKeyParameter senderPublicKey = GetSenderPublicKey( receiverPrivateKey, info.Originator); - KeyParameter agreedWrapKey = CalculateAgreedWrapKey(wrapAlg, - senderPublicKey, receiverPrivateKey); + KeyParameter agreedWrapKey = CalculateAgreedWrapKey(wrapAlgOid, senderPublicKey, receiverPrivateKey); - return UnwrapSessionKey(wrapAlg, agreedWrapKey); + return UnwrapSessionKey(wrapAlgOid, agreedWrapKey); } catch (SecurityUtilityException e) { |