The class is currently not thread-safe. A naive thread safe implementation existed but was removed: #69
We could use a thread-safe cache pattern, as proposed here. Something like this;
public class SRP6RandomEphemeral {
private FinalWrapper wrapper;
// ...
public Bytes bytes(ByteOrder preferredOrder) {
FinalWrapper w = wrapper;
if (w == null) { // check 1
synchronized(this) {
w = wrapper;
if (w == null) { // check2
// Compute random BigInteger r
// ...
w = new FinalWrapper(new SRP6CustomIntegerVariable(r));
wrapper = w;
}
}
}
return w.instance.bytes(preferredOrder);
}
private static class FinalWrapper {
public final SRP6IntegerVariable instance;
public FinalWrapper(SRP6IntegerVariable instance) {
this.instance = instance;
}
}
}
The class is currently not thread-safe. A naive thread safe implementation existed but was removed: #69
We could use a thread-safe cache pattern, as proposed here. Something like this;