|
| 1 | +package scheme.CH.CH_KEF_DLP_LLA_2012; |
| 2 | + |
| 3 | +import base.GroupParam.MCL.SingleGroup; |
| 4 | +import com.herumi.mcl.Fr; |
| 5 | +import com.herumi.mcl.GT; |
| 6 | +import com.herumi.mcl.Mcl; |
| 7 | +import utils.Hash; |
| 8 | + |
| 9 | +import java.util.HashMap; |
| 10 | +import java.util.Map; |
| 11 | + |
| 12 | +@SuppressWarnings({"DuplicatedCode", "SuspiciousNameCombination"}) |
| 13 | +public class MCL_GT { |
| 14 | + public static class Label { |
| 15 | + public GT L = new GT(), R = new GT(); |
| 16 | + } |
| 17 | + |
| 18 | + public static class LabelGen { |
| 19 | + public GT y_1 = new GT(), omega_1 = new GT(); |
| 20 | + } |
| 21 | + |
| 22 | + public static class LabelManager { |
| 23 | + public Map<String, LabelGen> Dict = new HashMap<>(); |
| 24 | + public PublicParam pp; |
| 25 | + |
| 26 | + public LabelManager(PublicParam pp) { |
| 27 | + this.pp = pp; |
| 28 | + } |
| 29 | + |
| 30 | + public void add(PublicKey pk, LabelGen lg) { |
| 31 | + Dict.put(pk.toString(), lg); |
| 32 | + } |
| 33 | + |
| 34 | + public void get(Label L, PublicKey pk) { |
| 35 | + get(L, pk, new GT[]{new GT()}, new Fr[]{new Fr()}); |
| 36 | + } |
| 37 | + |
| 38 | + public void get(Label L, PublicKey pk, GT[] G_tmp, Fr[] Fr_tmp) { |
| 39 | + pp.GP.GetGElement(G_tmp[0]); |
| 40 | + pp.H2(Fr_tmp[0], G_tmp[0]); |
| 41 | + LabelGen lg = Dict.get(pk.toString()); |
| 42 | + Mcl.pow(L.L, lg.y_1, Fr_tmp[0]); |
| 43 | + Mcl.pow(L.R, lg.omega_1, Fr_tmp[0]); |
| 44 | + Mcl.mul(L.R, G_tmp[0], L.R); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + public static class PublicParam { |
| 49 | + public SingleGroup.SingleGroupGT GP = new SingleGroup.SingleGroupGT(); |
| 50 | + |
| 51 | + public void H1(Fr res, GT m1, GT m2, GT m3) { |
| 52 | + Hash.H_MCL_Zr_1(res, String.format("%s|%s|%s", m1, m2, m3)); |
| 53 | + } |
| 54 | + |
| 55 | + public void H2(Fr res, GT m1) { |
| 56 | + Hash.H_MCL_Zr_1(res, m1.toString()); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + public static class PublicKey { |
| 61 | + public GT g = new GT(), y_2 = new GT(); |
| 62 | + |
| 63 | + public String toString() { |
| 64 | + return String.format("%s|%s", g, y_2); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + public static class SecretKey { |
| 69 | + public Fr alpha = new Fr(), x_1 = new Fr(), x_2 = new Fr(); |
| 70 | + } |
| 71 | + |
| 72 | + public static class HashValue { |
| 73 | + public GT S = new GT(); |
| 74 | + } |
| 75 | + |
| 76 | + public static class Randomness { |
| 77 | + Fr r = new Fr(); |
| 78 | + } |
| 79 | + |
| 80 | + private final GT[] G_tmp = new GT[]{new GT(), new GT()}; |
| 81 | + private final Fr[] Fr_tmp = new Fr[]{new Fr(), new Fr()}; |
| 82 | + |
| 83 | + private void getHashValue(GT res, Randomness r, Label L, PublicParam PP, PublicKey pk, Fr m) { |
| 84 | + Mcl.pow(res, pk.g, m); |
| 85 | + PP.H1(Fr_tmp[0], L.L, L.R, L.L); |
| 86 | + Mcl.pow(G_tmp[0], pk.y_2, Fr_tmp[0]); |
| 87 | + Mcl.mul(G_tmp[0], G_tmp[0], L.L); |
| 88 | + Mcl.pow(G_tmp[0], G_tmp[0], r.r); |
| 89 | + Mcl.mul(res, res, G_tmp[0]); |
| 90 | + } |
| 91 | + |
| 92 | + public void KeyGen(PublicKey pk, SecretKey sk, PublicParam PP, LabelManager LM) { |
| 93 | + PP.GP.GetGElement(pk.g); |
| 94 | + PP.GP.GetZrElement(sk.alpha); |
| 95 | + PP.GP.GetZrElement(sk.x_1); |
| 96 | + PP.GP.GetZrElement(sk.x_2); |
| 97 | + LabelGen lg = new LabelGen(); |
| 98 | + Mcl.pow(lg.y_1, pk.g, sk.x_1); |
| 99 | + Mcl.pow(pk.y_2, pk.g, sk.x_2); |
| 100 | + |
| 101 | + Mcl.pow(lg.omega_1, lg.y_1, sk.alpha); |
| 102 | + LM.add(pk, lg); |
| 103 | + } |
| 104 | + |
| 105 | + public void Hash(HashValue h, Randomness r, Label L, PublicParam PP, LabelManager LM, PublicKey pk, Fr m) { |
| 106 | + LM.get(L, pk, G_tmp, Fr_tmp); |
| 107 | + PP.GP.GetZrElement(r.r); |
| 108 | + getHashValue(h.S, r, L, PP, pk, m); |
| 109 | + } |
| 110 | + |
| 111 | + public boolean Check(HashValue h, Randomness r, PublicParam PP, PublicKey pk, Label L, Fr m) { |
| 112 | + getHashValue(G_tmp[1], r, L, PP, pk, m); |
| 113 | + return h.S.equals(G_tmp[1]); |
| 114 | + } |
| 115 | + |
| 116 | + public void UForge(Randomness r_p, HashValue h, Randomness r, Label L, PublicParam PP, PublicKey pk, SecretKey sk, Fr m, Fr m_p) { |
| 117 | + if (!Check(h, r, PP, pk, L, m)) throw new RuntimeException("illegal hash"); |
| 118 | + Mcl.pow(G_tmp[0], L.L, sk.alpha); |
| 119 | + Mcl.inv(G_tmp[0], G_tmp[0]); |
| 120 | + Mcl.mul(G_tmp[0], L.R, G_tmp[0]); |
| 121 | + |
| 122 | + PP.H2(Fr_tmp[0], G_tmp[0]); |
| 123 | + |
| 124 | + Mcl.pow(G_tmp[0], pk.g, sk.x_1); |
| 125 | + Mcl.pow(G_tmp[0], G_tmp[0], Fr_tmp[0]); |
| 126 | + Mcl.mul(Fr_tmp[0], sk.x_1, Fr_tmp[0]); |
| 127 | + Mcl.pow(G_tmp[0], pk.g, Fr_tmp[0]); |
| 128 | + if (!G_tmp[0].equals(L.L)) throw new RuntimeException("illegal label"); |
| 129 | + |
| 130 | + PP.H1(Fr_tmp[1], L.L, L.R, L.L); |
| 131 | + Mcl.mul(Fr_tmp[1], sk.x_2, Fr_tmp[1]); |
| 132 | + Mcl.add(Fr_tmp[1], Fr_tmp[0], Fr_tmp[1]); |
| 133 | + Mcl.sub(r_p.r, m, m_p); |
| 134 | + Mcl.div(r_p.r, r_p.r, Fr_tmp[1]); |
| 135 | + Mcl.add(r_p.r, r.r, r_p.r); |
| 136 | + } |
| 137 | + |
| 138 | + public void IForge(Randomness r_pp, Randomness r, Randomness r_p, Fr m, Fr m_p, Fr m_pp) { |
| 139 | + Mcl.sub(r_pp.r, r_p.r, r.r); |
| 140 | + Mcl.sub(Fr_tmp[0], m_p, m_pp); |
| 141 | + Mcl.mul(r_pp.r, r_pp.r, Fr_tmp[0]); |
| 142 | + Mcl.sub(Fr_tmp[0], m, m_p); |
| 143 | + Mcl.div(r_pp.r, r_pp.r, Fr_tmp[0]); |
| 144 | + Mcl.add(r_pp.r, r_p.r, r_pp.r); |
| 145 | + } |
| 146 | +} |
0 commit comments