Skip to content

Make SRP6RandomEphemeral thread safe #90

Description

@Glusk

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;
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions