Debian Codegraph @

ext/ed25519_jruby/net/i2p/crypto/eddsa/spec/EdDSANamedCurveTable.java

raw symbols SCIP
1 /**
2 * EdDSA-Java by str4d
3 *
4 * To the extent possible under law, the person who associated CC0 with
5 * EdDSA-Java has waived all copyright and related or neighboring rights
6 * to EdDSA-Java.
7 *
8 * You should have received a copy of the CC0 legalcode along with this
9 * work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
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 * The named EdDSA curves.
25 * @author str4d
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, // b
33 Utils.hexToBytes("edffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f"), // q
34 new Ed25519LittleEndianEncoding());
35
36 private static final Curve ed25519curve = new Curve(ed25519field,
37 Utils.hexToBytes("a3785913ca4deb75abd841414d0a700098e879777940c78c73fe6f2bee6c0352"), // d
38 ed25519field.fromByteArray(Utils.hexToBytes("b0a00e4a271beec478e42fad0618432fa7d7fb3d99004d2b0bdfc14f8024832b"))); // I
39
40 private static final EdDSANamedCurveSpec ed25519 = new EdDSANamedCurveSpec(
41 ED_25519,
42 ed25519curve,
43 "SHA-512", // H
44 new Ed25519ScalarOps(), // l
45 ed25519curve.createPoint( // B
46 Utils.hexToBytes("5866666666666666666666666666666666666666666666666666666666666666"),
47 true)); // Precompute tables for B
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 // RFC 8032
65 defineCurve(ed25519);
66 }
67
68 public static EdDSANamedCurveSpec getByName(String name) {
69 return curves.get(name.toLowerCase(Locale.ENGLISH));
70 }
71 }