Skip to content

Commit 92887ae

Browse files
committed
Lazy init of -A
1 parent 6d458bb commit 92887ae

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/net/i2p/crypto/eddsa/spec/EdDSAPublicKeySpec.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
public class EdDSAPublicKeySpec implements KeySpec {
2323
private final GroupElement A;
24-
private final GroupElement Aneg;
24+
private GroupElement Aneg;
2525
private final EdDSAParameterSpec spec;
2626

2727
/**
@@ -34,8 +34,6 @@ public EdDSAPublicKeySpec(byte[] pk, EdDSAParameterSpec spec) {
3434
throw new IllegalArgumentException("public-key length is wrong");
3535

3636
this.A = new GroupElement(spec.getCurve(), pk);
37-
// Precompute -A for use in verification.
38-
this.Aneg = A.negate();
3937
this.spec = spec;
4038
}
4139

@@ -50,7 +48,13 @@ public GroupElement getA() {
5048
}
5149

5250
public GroupElement getNegativeA() {
53-
return Aneg;
51+
// Only read Aneg once, otherwise read re-ordering might occur between here and return.
52+
GroupElement ourAneg = Aneg;
53+
if(ourAneg == null) {
54+
ourAneg = A.negate();
55+
Aneg = ourAneg;
56+
}
57+
return ourAneg;
5458
}
5559

5660
public EdDSAParameterSpec getParams() {

0 commit comments

Comments
 (0)