diff options
Diffstat (limited to 'crypto/src/openpgp')
-rw-r--r-- | crypto/src/openpgp/PgpSignatureGenerator.cs | 24 | ||||
-rw-r--r-- | crypto/src/openpgp/PgpV3SignatureGenerator.cs | 23 |
2 files changed, 24 insertions, 23 deletions
diff --git a/crypto/src/openpgp/PgpSignatureGenerator.cs b/crypto/src/openpgp/PgpSignatureGenerator.cs index 12edf9f89..64d256653 100644 --- a/crypto/src/openpgp/PgpSignatureGenerator.cs +++ b/crypto/src/openpgp/PgpSignatureGenerator.cs @@ -40,36 +40,34 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp } /// <summary>Initialise the generator for signing.</summary> - public void InitSign( - int sigType, - PgpPrivateKey privKey) + public void InitSign(int sigType, PgpPrivateKey privKey) { InitSign(sigType, privKey, null); } /// <summary>Initialise the generator for signing.</summary> - public void InitSign( - int sigType, - PgpPrivateKey privKey, - SecureRandom random) + public void InitSign(int sigType, PgpPrivateKey privKey, SecureRandom random) { this.privKey = privKey; this.signatureType = sigType; AsymmetricKeyParameter key = privKey.Key; - if (sig == null) - { - this.sig = PgpUtilities.CreateSigner(keyAlgorithm, hashAlgorithm, key); - } + this.sig = PgpUtilities.CreateSigner(keyAlgorithm, hashAlgorithm, key); try { ICipherParameters cp = key; - if (random != null) + + // TODO Ask SignerUtilities whether random is permitted? + if (keyAlgorithm == PublicKeyAlgorithmTag.EdDsa) { - cp = new ParametersWithRandom(cp, random); + // EdDSA signers don't expect a SecureRandom } + else + { + cp = ParameterUtilities.WithRandom(cp, random); + } sig.Init(true, cp); } diff --git a/crypto/src/openpgp/PgpV3SignatureGenerator.cs b/crypto/src/openpgp/PgpV3SignatureGenerator.cs index 324dbd768..03dd8795d 100644 --- a/crypto/src/openpgp/PgpV3SignatureGenerator.cs +++ b/crypto/src/openpgp/PgpV3SignatureGenerator.cs @@ -47,20 +47,23 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp AsymmetricKeyParameter key = privKey.Key; - if (sig == null) - { - this.sig = PgpUtilities.CreateSigner(keyAlgorithm, hashAlgorithm, key); - } + this.sig = PgpUtilities.CreateSigner(keyAlgorithm, hashAlgorithm, key); try { - ICipherParameters cp = key; - if (random != null) - { - cp = new ParametersWithRandom(cp, random); - } + ICipherParameters cp = key; + + // TODO Ask SignerUtilities whether random is permitted? + if (keyAlgorithm == PublicKeyAlgorithmTag.EdDsa) + { + // EdDSA signers don't expect a SecureRandom + } + else + { + cp = ParameterUtilities.WithRandom(cp, random); + } - sig.Init(true, cp); + sig.Init(true, cp); } catch (InvalidKeyException e) { |