private static void pickSatisfyMinLeaves(BswabePolicy p, BswabePrv prv) { int i, k, l, c_i; int len; ArrayList<Integer> c = new ArrayList<Integer>(); if (p.children == null || p.children.length == 0) p.min_leaves = 1; else { len = p.children.length; for (i = 0; i < len; i++) if (p.children[i].satisfiable) pickSatisfyMinLeaves(p.children[i], prv); for (i = 0; i < len; i++) c.add(new Integer(i)); Collections.sort(c, new IntegerComparator(p)); p.satl = new ArrayList<Integer>(); p.min_leaves = 0; l = 0; for (i = 0; i < len && l < p.k; i++) { c_i = c.get(i).intValue(); /* c[i] */ if (p.children[c_i].satisfiable) { l++; p.min_leaves += p.children[c_i].min_leaves; k = c_i + 1; p.satl.add(new Integer(k)); } } } }
public static BswabeElementBoolean dec(BswabePub pub, BswabePrv prv, BswabeCph cph) { Element t; Element m; BswabeElementBoolean beb = new BswabeElementBoolean(); m = pub.p.getGT().newElement(); t = pub.p.getGT().newElement(); checkSatisfy(cph.p, prv); if (!cph.p.satisfiable) { System.err .println("cannot decrypt, attributes in key do not satisfy policy"); beb.e = null; beb.b = false; return beb; } pickSatisfyMinLeaves(cph.p, prv); decFlatten(t, cph.p, prv, pub); m = cph.cs.duplicate(); m.mul(t); /* num_muls++; */ t = pub.p.pairing(cph.c, prv.d); t.invert(); m.mul(t); /* num_muls++; */ beb.e = m; beb.b = true; return beb; }