| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
package net.i2p.crypto.eddsa.spec; |
| 13 |
|
| 14 |
import java.security.MessageDigest; |
| 15 |
import java.security.NoSuchAlgorithmException; |
| 16 |
import java.security.spec.AlgorithmParameterSpec; |
| 17 |
|
| 18 |
import net.i2p.crypto.eddsa.math.Curve; |
| 19 |
import net.i2p.crypto.eddsa.math.GroupElement; |
| 20 |
import net.i2p.crypto.eddsa.math.ScalarOps; |
| 21 |
|
| 22 |
import java.io.Serializable; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class EdDSAParameterSpec implements AlgorithmParameterSpec, Serializable { |
| 30 |
private static final long serialVersionUID = 8274987108472012L; |
| 31 |
private final Curve curve; |
| 32 |
private final String hashAlgo; |
| 33 |
private final ScalarOps sc; |
| 34 |
private final GroupElement B; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public EdDSAParameterSpec(Curve curve, String hashAlgo, |
| 44 |
ScalarOps sc, GroupElement B) { |
| 45 |
try { |
| 46 |
MessageDigest hash = MessageDigest.getInstance(hashAlgo); |
| 47 |
|
| 48 |
if (curve.getField().getb()/4 != hash.getDigestLength()) |
| 49 |
throw new IllegalArgumentException("Hash output is not 2b-bit"); |
| 50 |
} catch (NoSuchAlgorithmException e) { |
| 51 |
throw new IllegalArgumentException("Unsupported hash algorithm"); |
| 52 |
} |
| 53 |
|
| 54 |
this.curve = curve; |
| 55 |
this.hashAlgo = hashAlgo; |
| 56 |
this.sc = sc; |
| 57 |
this.B = B; |
| 58 |
} |
| 59 |
|
| 60 |
public Curve getCurve() { |
| 61 |
return curve; |
| 62 |
} |
| 63 |
|
| 64 |
public String getHashAlgorithm() { |
| 65 |
return hashAlgo; |
| 66 |
} |
| 67 |
|
| 68 |
public ScalarOps getScalarOps() { |
| 69 |
return sc; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public GroupElement getB() { |
| 76 |
return B; |
| 77 |
} |
| 78 |
|
| 79 |
@Override |
| 80 |
public int hashCode() { |
| 81 |
return hashAlgo.hashCode() ^ |
| 82 |
curve.hashCode() ^ |
| 83 |
B.hashCode(); |
| 84 |
} |
| 85 |
|
| 86 |
@Override |
| 87 |
public boolean equals(Object o) { |
| 88 |
if (o == this) |
| 89 |
return true; |
| 90 |
if (!(o instanceof EdDSAParameterSpec)) |
| 91 |
return false; |
| 92 |
EdDSAParameterSpec s = (EdDSAParameterSpec) o; |
| 93 |
return hashAlgo.equals(s.getHashAlgorithm()) && |
| 94 |
curve.equals(s.getCurve()) && |
| 95 |
B.equals(s.getB()); |
| 96 |
} |
| 97 |
} |