Skip to content

Commit

Permalink
GH470: Synchronize access to a shared KeyPairGenerator, which may not…
Browse files Browse the repository at this point in the history
… be thread-safe.

The keyPairGenerator object in the MontgomeryCurve is a bouncycastle implementation
of the java.security.KeyPairGenerator class. The generateKeyPair method in class
org.bouncycastle.jcajce.provider.asymmetric.edec.KeyPairGeneratorSpi is not thread safe,
so calling the keyPairGenerator.generateKeyPair method must be synchronized.
  • Loading branch information
zakharovsergey1000 committed Feb 25, 2024
1 parent 2c62c72 commit a90aa9f
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ public Digest createDigest() {
}

public KeyPair generateKeyPair() {
return keyPairGenerator.generateKeyPair();
synchronized (this) {
return keyPairGenerator.generateKeyPair();
}
}

public byte[] encode(PublicKey key) throws InvalidKeyException {
Expand Down

0 comments on commit a90aa9f

Please sign in to comment.