I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 134cbd46 authored by zzz's avatar zzz
Browse files

Crypto: Enforce correct seed and hash lengths in EdDSAPrivateKeySpec

parent 91007735
No related branches found
No related tags found
No related merge requests found
...@@ -21,9 +21,12 @@ public class EdDSAPrivateKeySpec implements KeySpec { ...@@ -21,9 +21,12 @@ public class EdDSAPrivateKeySpec implements KeySpec {
private final EdDSAParameterSpec spec; private final EdDSAParameterSpec spec;
/** /**
* @throws IllegalArgumentException if hash algorithm is unsupported * @throws IllegalArgumentException if seed length is wrong or hash algorithm is unsupported
*/ */
public EdDSAPrivateKeySpec(byte[] seed, EdDSAParameterSpec spec) { public EdDSAPrivateKeySpec(byte[] seed, EdDSAParameterSpec spec) {
if (seed.length != spec.getCurve().getField().getb()/8)
throw new IllegalArgumentException("seed length is wrong");
this.spec = spec; this.spec = spec;
this.seed = seed; this.seed = seed;
...@@ -56,9 +59,13 @@ public class EdDSAPrivateKeySpec implements KeySpec { ...@@ -56,9 +59,13 @@ public class EdDSAPrivateKeySpec implements KeySpec {
* getSeed() will return null if this constructor is used. * getSeed() will return null if this constructor is used.
* *
* @param h the private key * @param h the private key
* @throws IllegalArgumentException if hash length is wrong
* @since 0.9.27 (GitHub issue #17) * @since 0.9.27 (GitHub issue #17)
*/ */
public EdDSAPrivateKeySpec(EdDSAParameterSpec spec, byte[] h) { public EdDSAPrivateKeySpec(EdDSAParameterSpec spec, byte[] h) {
if (h.length != spec.getCurve().getField().getb()/4)
throw new IllegalArgumentException("hash length is wrong");
this.seed = null; this.seed = null;
this.h = h; this.h = h;
this.spec = spec; this.spec = spec;
...@@ -77,7 +84,7 @@ public class EdDSAPrivateKeySpec implements KeySpec { ...@@ -77,7 +84,7 @@ public class EdDSAPrivateKeySpec implements KeySpec {
this.h = h; this.h = h;
this.a = a; this.a = a;
this.A = A; this.A = A;
this.spec = spec; this.spec = spec;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment