Skip to content

Commit f09ecb5

Browse files
committed
JSSE: synchronize methods in WolfCryptRandom
1 parent 8a59eaf commit f09ecb5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/main/java/com/wolfssl/provider/jce/WolfCryptRandom.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ public WolfCryptRandom() {
5252
}
5353

5454
@Override
55-
protected byte[] engineGenerateSeed(int numBytes) {
55+
protected synchronized byte[] engineGenerateSeed(int numBytes) {
5656

5757
return rng.generateBlock(numBytes);
5858
}
5959

6060
@Override
61-
protected void engineNextBytes(byte[] bytes) {
61+
protected synchronized void engineNextBytes(byte[] bytes) {
6262

6363
rng.generateBlock(bytes);
6464
}
6565

6666
@Override
67-
protected void engineSetSeed(byte[] seed) {
67+
protected synchronized void engineSetSeed(byte[] seed) {
6868
/* wolfCrypt reseeds internally automatically */
6969
log("setSeed() not supported by wolfJCE");
7070
}
@@ -75,7 +75,7 @@ private void log(String msg) {
7575

7676
@SuppressWarnings("deprecation")
7777
@Override
78-
protected void finalize() throws Throwable {
78+
protected synchronized void finalize() throws Throwable {
7979
try {
8080

8181
if (this.rng != null) {
@@ -98,7 +98,9 @@ protected void finalize() throws Throwable {
9898
*
9999
* @throws IOException on error writing to ObjectOutputStream
100100
*/
101-
private void writeObject(ObjectOutputStream out) throws IOException {
101+
private synchronized void writeObject(ObjectOutputStream out)
102+
throws IOException {
103+
102104
if (this.rng != null) {
103105
this.rng.free();
104106
this.rng.releaseNativeStruct();
@@ -118,7 +120,7 @@ private void writeObject(ObjectOutputStream out) throws IOException {
118120
* @throws IOException on error reading from ObjectInputStream
119121
* @throws ClassNotFoundException if object class not found
120122
*/
121-
private void readObject(ObjectInputStream in)
123+
private synchronized void readObject(ObjectInputStream in)
122124
throws IOException, ClassNotFoundException {
123125

124126
if (rng == null) {

0 commit comments

Comments
 (0)