| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
package net.i2p.crypto.eddsa.spec; |
| 13 |
|
| 14 |
import java.util.Hashtable; |
| 15 |
import java.util.Locale; |
| 16 |
|
| 17 |
import net.i2p.crypto.eddsa.Utils; |
| 18 |
import net.i2p.crypto.eddsa.math.Curve; |
| 19 |
import net.i2p.crypto.eddsa.math.Field; |
| 20 |
import net.i2p.crypto.eddsa.math.ed25519.Ed25519LittleEndianEncoding; |
| 21 |
import net.i2p.crypto.eddsa.math.ed25519.Ed25519ScalarOps; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class EdDSANamedCurveTable { |
| 29 |
public static final String ED_25519 = "Ed25519"; |
| 30 |
|
| 31 |
private static final Field ed25519field = new Field( |
| 32 |
256, |
| 33 |
Utils.hexToBytes("edffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f"), |
| 34 |
new Ed25519LittleEndianEncoding()); |
| 35 |
|
| 36 |
private static final Curve ed25519curve = new Curve(ed25519field, |
| 37 |
Utils.hexToBytes("a3785913ca4deb75abd841414d0a700098e879777940c78c73fe6f2bee6c0352"), |
| 38 |
ed25519field.fromByteArray(Utils.hexToBytes("b0a00e4a271beec478e42fad0618432fa7d7fb3d99004d2b0bdfc14f8024832b"))); |
| 39 |
|
| 40 |
private static final EdDSANamedCurveSpec ed25519 = new EdDSANamedCurveSpec( |
| 41 |
ED_25519, |
| 42 |
ed25519curve, |
| 43 |
"SHA-512", |
| 44 |
new Ed25519ScalarOps(), |
| 45 |
ed25519curve.createPoint( |
| 46 |
Utils.hexToBytes("5866666666666666666666666666666666666666666666666666666666666666"), |
| 47 |
true)); |
| 48 |
|
| 49 |
private static final Hashtable<String, EdDSANamedCurveSpec> curves = new Hashtable<String, EdDSANamedCurveSpec>(); |
| 50 |
|
| 51 |
public static void defineCurve(EdDSANamedCurveSpec curve) { |
| 52 |
curves.put(curve.getName().toLowerCase(Locale.ENGLISH), curve); |
| 53 |
} |
| 54 |
|
| 55 |
static void defineCurveAlias(String name, String alias) { |
| 56 |
EdDSANamedCurveSpec curve = curves.get(name.toLowerCase(Locale.ENGLISH)); |
| 57 |
if (curve == null) { |
| 58 |
throw new IllegalStateException(); |
| 59 |
} |
| 60 |
curves.put(alias.toLowerCase(Locale.ENGLISH), curve); |
| 61 |
} |
| 62 |
|
| 63 |
static { |
| 64 |
|
| 65 |
defineCurve(ed25519); |
| 66 |
} |
| 67 |
|
| 68 |
public static EdDSANamedCurveSpec getByName(String name) { |
| 69 |
return curves.get(name.toLowerCase(Locale.ENGLISH)); |
| 70 |
} |
| 71 |
} |