Skip to content

Commit 78aabab

Browse files
zzzstr4d
authored andcommitted
Add private key spec constructor for hash, update javadocs
Closes #17
1 parent a48ee14 commit 78aabab

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

src/net/i2p/crypto/eddsa/EdDSAPrivateKey.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ public String getFormat() {
9696
* This will hopefully be clarified in the next draft.
9797
* But sun.security.pkcs.PKCS8Key expects them so we must include them for keytool to work.
9898
*
99+
* This encodes the seed. It will return null if constructed from
100+
* a spec which was directly constructed from H, in which case seed is null.
101+
*
99102
* @return 49 bytes for Ed25519, null for other curves
100103
*/
101104
public byte[] getEncoded() {
@@ -178,22 +181,38 @@ public EdDSAParameterSpec getParams() {
178181
return edDsaSpec;
179182
}
180183

184+
/**
185+
* @return will be null if constructed from a spec which was
186+
* directly constructed from H
187+
*/
181188
public byte[] getSeed() {
182189
return seed;
183190
}
184191

192+
/**
193+
* @return the hash of the seed
194+
*/
185195
public byte[] getH() {
186196
return h;
187197
}
188198

199+
/**
200+
* @return the private key
201+
*/
189202
public byte[] geta() {
190203
return a;
191204
}
192205

206+
/**
207+
* @return the public key
208+
*/
193209
public GroupElement getA() {
194210
return A;
195211
}
196212

213+
/**
214+
* @return the public key
215+
*/
197216
public byte[] getAbyte() {
198217
return Abyte;
199218
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public ScalarOps getScalarOps() {
6565
return sc;
6666
}
6767

68+
/**
69+
* @return the base (generator)
70+
*/
6871
public GroupElement getB() {
6972
return B;
7073
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ public EdDSAPrivateKeySpec(byte[] seed, EdDSAParameterSpec spec) {
6060
}
6161
}
6262

63+
/**
64+
* Initialize directly from the hash.
65+
* getSeed() will return null if this constructor is used.
66+
*
67+
* @param h the private key
68+
* @since 0.1.1
69+
*/
70+
public EdDSAPrivateKeySpec(EdDSAParameterSpec spec, byte[] h) {
71+
this.seed = null;
72+
this.h = h;
73+
this.spec = spec;
74+
int b = spec.getCurve().getField().getb();
75+
76+
h[0] &= 248;
77+
h[(b/8)-1] &= 63;
78+
h[(b/8)-1] |= 64;
79+
a = Arrays.copyOfRange(h, 0, b/8);
80+
81+
A = spec.getB().scalarMultiply(a);
82+
}
83+
6384
public EdDSAPrivateKeySpec(byte[] seed, byte[] h, byte[] a, GroupElement A, EdDSAParameterSpec spec) {
6485
this.seed = seed;
6586
this.h = h;
@@ -68,18 +89,30 @@ public EdDSAPrivateKeySpec(byte[] seed, byte[] h, byte[] a, GroupElement A, EdDS
6889
this.spec = spec;
6990
}
7091

92+
/**
93+
* @return will be null if constructed directly from the private key
94+
*/
7195
public byte[] getSeed() {
7296
return seed;
7397
}
7498

99+
/**
100+
* @return the hash
101+
*/
75102
public byte[] getH() {
76103
return h;
77104
}
78105

106+
/**
107+
* @return the private key
108+
*/
79109
public byte[] geta() {
80110
return a;
81111
}
82112

113+
/**
114+
* @return the public key
115+
*/
83116
public GroupElement getA() {
84117
return A;
85118
}

0 commit comments

Comments
 (0)