本文整理汇总了Java中it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory类的典型用法代码示例。如果您正苦于以下问题:Java PairingFactory类的具体用法?Java PairingFactory怎么用?Java PairingFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PairingFactory类属于it.unisa.dia.gas.plaf.jpbc.pairing包,在下文中一共展示了PairingFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createParameters
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
@Override
public IPLOSTW10Parameters createParameters(int n, String keyPath) {
PairingFactory.getInstance().setUsePBCWhenPossible(true);
int rBits = 160;
int qBits = 128;
TypeACurveGenerator pg = new TypeACurveGenerator(rBits, qBits);
PairingParameters pp = pg.generate();
// save pairing parameters
Common.writeFile(keyPath + "/pairing.properties", pp.toString()
.getBytes());
return new IPLOSTW10ParametersGenerator().init(pp, n)
.generateParameters();
}
示例2: BLSCommittedSecretShareMessage
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
private BLSCommittedSecretShareMessage(BLS01Parameters blsParameters, ASN1Sequence seq)
{
this.index = ASN1Integer.getInstance(seq.getObjectAt(0)).getValue().intValue();
this.value = ASN1Integer.getInstance(seq.getObjectAt(1)).getValue();
this.witness = ASN1Integer.getInstance(seq.getObjectAt(2)).getValue();
ASN1Sequence s = ASN1Sequence.getInstance(seq.getObjectAt(3));
this.commitmentFactors = new Element[s.size()];
for (int i = 0; i != commitmentFactors.length; i++)
{
commitmentFactors[i] = blsParameters.getG().duplicate();
commitmentFactors[i].setFromBytes(DEROctetString.getInstance(s.getObjectAt(i)).getOctets());
}
Pairing pairing = PairingFactory.getPairing(blsParameters.getCurveParameters());
this.pK = pairing.getG2().newElement();
this.pK.setFromBytes(DEROctetString.getInstance(seq.getObjectAt(4)).getOctets());
}
示例3: initialize
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
@Override
public void initialize() {
if (forEncryption) {
if (!(key instanceof FEEncryptionParameters))
throw new IllegalArgumentException("FEEncryptionParameters are required for encryption.");
} else {
if (!(key instanceof IPLOSTW10SecretKeyParameters))
throw new IllegalArgumentException("IPLOSTW10SecretKeyParameters are required for decryption.");
}
IPLOSTW10KeyParameters ipKey = (IPLOSTW10KeyParameters) key;
this.n = ipKey.getParameters().getN();
int N = (2 * n + 3);
this.pairing = PairingFactory.getPairing(ipKey.getParameters().getParameters());
this.productPairing = new ProductPairing(null, pairing, N);
this.keyBytes = pairing.getGT().getLengthInBytes();
this.outBytes = 2 * pairing.getGT().getLengthInBytes() + N * pairing.getG1().getLengthInBytes();
}
示例4: split
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
/**
* Given the secret generate random coefficients (except for a_0 which is
* the secret) and compute the function for each privacy peer (who is
* assigned a dedicated alpha). Coefficients are picked from (0, fieldSize).
*
* @param secret the secret to be shared
* @return the shares of the secret for each privacy peer
*/
public BLSCommittedSplitSecret split(BigInteger secret)
{
// a polynomial
SplitSecret secretShares = secretSplitter.split(secret);
// b polynomial
SplitSecret bShares = secretSplitter.split(getRandomInteger(PairingFactory.getPairing(domainParams.getCurveParameters()).getZr().getOrder(), random));
Element[] commitments = new Element[k];
for (int j = 0; j < k; j++)
{
commitments[j] = domainParams.getG().mul(secretShares.getCoefficients()[j]).add(h.mul(bShares.getCoefficients()[j]));
}
return new BLSCommittedSplitSecret(secretShares.getShares(), secretShares.getCoefficients(), bShares.getShares(), commitments);
}
示例5: fetchPartialPublicKey
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
@Override
public PartialPublicKeyInfo fetchPartialPublicKey(String keyID)
throws IOException
{
if (sharedPrivateKeyMap.containsKey(keyID))
{
BLS01Parameters params = paramsMap.get(keyID);
Share<BigInteger> share = sharedPrivateKeyMap.getShare(keyID, TIME_OUT, TimeUnit.SECONDS);
Pairing pairing = PairingFactory.getPairing(params.getCurveParameters());
Element g = params.getG();
// calculate the public key
Element sk = pairing.getZr().newElement(share.getValue());
Element pk = g.powZn(sk);
return new PartialPublicKeyInfo(share.getSequenceNo(), SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(new BLS01PublicKeyParameters(params, pk.getImmutable())));
}
return null;
}
示例6: unserializeBswabePub
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
public static BswabePub unserializeBswabePub(byte[] b) {
BswabePub pub;
int offset;
pub = new BswabePub();
offset = 0;
StringBuffer sb = new StringBuffer("");
offset = unserializeString(b, offset, sb);
pub.pairingDesc = sb.substring(0);
PropertiesParameters params = new PropertiesParameters()
.load(new ByteArrayInputStream(pub.pairingDesc.getBytes()));
pub.p = PairingFactory.getPairing(params);
// pub.p=PairingFactory.getPairing("params/curves/a.properties");
Pairing pairing = pub.p;
pub.g = pairing.getG1().newElement();
pub.h = pairing.getG1().newElement();
pub.gp = pairing.getG2().newElement();
pub.g_hat_alpha = pairing.getGT().newElement();
offset = unserializeElement(b, offset, pub.g);
offset = unserializeElement(b, offset, pub.h);
offset = unserializeElement(b, offset, pub.gp);
offset = unserializeElement(b, offset, pub.g_hat_alpha);
return pub;
}
示例7: main
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
prepareDirectory();
long timeStart = System.currentTimeMillis();
long timeEnd = System.currentTimeMillis();
System.out.println(String.format("this operation took %d ms.", timeEnd - timeStart));
System.out.println("wasPbcAvailable? " + PairingFactory.getInstance().isPBCAvailable());
}
示例8: getPairing
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
public Pairing getPairing() {
if (p == null) {
PairingParameters params = new PropertiesParameters().load(new ByteArrayInputStream(pairingDesc.getBytes()));
p = PairingFactory.getPairing(params);
}
return p;
}
示例9: generateSig
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
public MessageReply generateSig(SignatureCreateMessage blsCreate)
throws ServiceConnectionException, IOException
{
Participant[] participants = new Participant[blsCreate.getNodesToUse().size()];
int index = 0;
for (String name : blsCreate.getNodesToUse())
{
MessageReply seqRep = sendMessage(name, Type.FETCH_SEQUENCE_NO, new KeyIDMessage(blsCreate.getKeyID()));
// TODO: need to drop out people who don't reply.
participants[index] = new Participant(BigIntegerMessage.getInstance(seqRep.getPayload()).getValue().intValue(), name);
index++;
}
FetchPublicKeyMessage fetchMessage = new FetchPublicKeyMessage(blsCreate.getKeyID());
MessageReply reply = connection.sendMessage(ClientMessage.Type.FETCH_PUBLIC_KEY, fetchMessage);
SubjectPublicKeyInfo pubKeyInfo = SubjectPublicKeyInfo.getInstance(reply.getPayload());
BLS01Parameters domainParams = BLSPublicKeyFactory.createKey(pubKeyInfo).getParameters();
Pairing pairing = PairingFactory.getPairing(domainParams.getCurveParameters());
byte[] hash = blsCreate.getMessage();
Element h = pairing.getG1().newElement().setFromHash(hash, 0, hash.length);
// TODO: need to take into account node failure during startup.
Element signature = accumulateElement(participants, Type.PRIVATE_KEY_SIGN, new BLSPartialCreateMessage(blsCreate.getKeyID(), h, participants), pairing, pairing.getZr().getOrder());
signature = signature.powZn(pairing.getZr().newOneElement());
return new MessageReply(MessageReply.Type.OKAY, new DEROctetString(signature.toBytes()));
}
示例10: createKey
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
/**
* Create BLS01PublicKeyParameters from an ASN.1 encoding of a SubjectPublicKeyInfo object.
*
* @param publicKeyInfo the info structure containing the BLS public key.
* @return a BLS public key.
*/
public static BLS01PublicKeyParameters createKey(SubjectPublicKeyInfo publicKeyInfo)
{
AlgorithmIdentifier algId = publicKeyInfo.getAlgorithm();
CurveParameters curveParameters;
Element G;
Pairing pairing;
try
{
ASN1Sequence parameters = ASN1Sequence.getInstance(algId.getParameters());
curveParameters = new DefaultCurveParameters().load(new ByteArrayInputStream(DERUTF8String.getInstance(parameters.getObjectAt(0)).getString().getBytes("UTF8")));
pairing = PairingFactory.getPairing(curveParameters);
G = pairing.getG2().newElement();
G.setFromBytes(DEROctetString.getInstance(parameters.getObjectAt(1)).getOctets());
}
catch (IOException e)
{
throw new IllegalStateException("Unable to support encoding: " + e.getMessage(), e);
}
BLS01Parameters blsParameters = new BLS01Parameters(curveParameters, G.getImmutable());
Element pK = pairing.getG2().newElement();
pK.setFromBytes(publicKeyInfo.getPublicKeyData().getBytes());
return new BLS01PublicKeyParameters(blsParameters, pK.getImmutable());
}
示例11: BLSNewDKGSecretSplitter
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
/**
* creates an instance over the specified EC domain parameters
* to share secrets among the specified number of peers
*
* @param numberOfPeers the number of peers among which the secret is shared
* @param threshold number of peers that must be available for secret reconstruction,
* @param h value to calculate commitment polynomial against.
* @param domainParams domain parameters for the EC group to use.
* @param random a source of randomness,
*/
public BLSNewDKGSecretSplitter(int numberOfPeers, int threshold, Element h, BLS01Parameters domainParams, SecureRandom random)
{
if (numberOfPeers < threshold)
{
throw new IllegalArgumentException("numberOfPeers must at least be as big as the threshold value.");
}
this.k = threshold;
this.h = h;
this.domainParams = domainParams;
this.secretSplitter = new ShamirSecretSplitter(numberOfPeers, threshold, PairingFactory.getPairing(domainParams.getCurveParameters()).getZr().getOrder(), random);
this.random = random;
}
示例12: generateKeyPair
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
public synchronized AsymmetricCipherKeyPair generateKeyPair(String keyID, Algorithm algorithm, int numberOfPeers, NamedKeyGenParams keyGenParams)
{
BLS01Parameters domainParameters = paramsMap.get(keyID);
if (domainParameters == null)
{
BLS01KeyPairGenerator kpGen = new BLS01KeyPairGenerator();
CurveParameters curveParameters = new DefaultCurveParameters().load(this.getClass().getResourceAsStream("d62003-159-158.param"));
Random random = new Random(makeSeed(Strings.toByteArray(keyID))); // Need a consistent random... TODO: maybe a better way
Pairing pairing = PairingFactory.getInstance().getPairing(curveParameters, random);
Element g = pairing.getG2().newRandomElement();
// we have to do this as the JPBC library ignores the random number generator passed in as
// a parameter.
// TODO: need to sort out source of randomness.
random = new SecureRandom();
pairing = PairingFactory.getInstance().getPairing(curveParameters, random);
BLS01Parameters blsParameters = new BLS01Parameters(curveParameters, g.getImmutable());
kpGen.init(new BLS01KeyGenerationParameters((SecureRandom)random, blsParameters));
AsymmetricCipherKeyPair kp = kpGen.generateKeyPair();
sharedPrivateKeyMap.init(keyID, numberOfPeers);
sharedPublicKeyMap.init(keyID, numberOfPeers);
hMap.put(keyID, keyGenParams.getH());
paramsMap.put(keyID, blsParameters);
return kp;
}
else
{
throw new IllegalStateException("Key " + keyID + " already exists.");
}
}
示例13: loadQueryKey
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
@Override
public CipherParameters loadQueryKey(String queryKeyPath) {
Path secretKeyPath = Paths.get(queryKeyPath);
Path path = Paths.get(getKeyPath(),
"pairing.properties");
byte[] data;
try {
data = Files.readAllBytes(path);
PairingParameters params = new PropertiesParameters()
.load(new ByteArrayInputStream(data));
Pairing p = PairingFactory.getPairing(params);
byte[] secretKeyData = Files.readAllBytes(secretKeyPath);
PairingStreamReader skStreamParser = new PairingStreamReader(p,
secretKeyData, 0);
query[0] = skStreamParser.readString();
query[1] = skStreamParser.readString();
query[2] = skStreamParser.readString();
System.out.println("Query was: "+query[0]+" "+query[1]+" "+query[2]);
Element g1 = skStreamParser.readG1Element();
int n1 = skStreamParser.readInt();
int N = 2 * n1 + 3;
Pairing prodP = new ProductPairing(null, p, N);
IPLOSTW10Parameters parameters2 = new IPLOSTW10Parameters(params,
g1.getImmutable(), n1);
Element k = skStreamParser.readG1Element(prodP);
return new IPLOSTW10SecretKeyParameters(parameters2, k);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例14: createAttributeVectorForTriple
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
@Override
public Element[] createAttributeVectorForTriple(CipherParameters publicKey,
org.openrdf.model.Statement triple) {
Pairing pairing = PairingFactory
.getPairing(((FEPublicKeyParameters) publicKey).getParameters()
.getParameters());
Element[] result = new Element[4];
MessageDigest sha1;
try {
sha1 = MessageDigest.getInstance("SHA-1");
/***************************************************************/
/***************** Computing 3 Random Elements *****************/
/***************************************************************/
// Instant start = Instant.now();
Element r1 = pairing.getZr().newRandomElement().getImmutable();
Element r2 = pairing.getZr().newRandomElement().getImmutable();
// Duration dur = Duration.between(start, Instant.now());
/***************************************************************/
/***************************************************************/
/******************* Computing SPO Elements ********************/
/***************************************************************/
// start = Instant.now();
byte[] digestS = sha1.digest(triple.getSubject().stringValue()
.getBytes());
Element s = pairing.getZr()
.newElementFromHash(digestS, 0, digestS.length)
.getImmutable();
byte[] digestO = sha1.digest(triple.getObject().stringValue()
.getBytes());
Element o = pairing.getZr()
.newElementFromHash(digestO, 0, digestO.length)
.getImmutable();
// dur = Duration.between(start, Instant.now());
/***************************************************************/
/***************************************************************/
/***************** Computing Attribute Vector ******************/
/***************************************************************/
// start = Instant.now();
result[0] = r1.mul(s.negate());
result[1] = r1;
result[2] = r2.mul(o.negate());
result[3] = r2;
// dur = Duration.between(start, Instant.now());
// System.out.format("Attribute Vector generated in: %sms%n",
// dur.toMillis());
/***************************************************************/
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
示例15: createPredicateVectorForQuery
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory; //导入依赖的package包/类
@Override
public Element[] createPredicateVectorForQuery(
CipherParameters masterSecKey, String s, String p, String o) {
Pairing pairing = PairingFactory
.getPairing(((IPLOSTW10MasterSecretKeyParameters) masterSecKey)
.getParameters().getParameters());
Element[] result = new Element[4];
MessageDigest sha1;
try {
sha1 = MessageDigest.getInstance("SHA-1");
/***************************************************************/
/******************* Computing SPO Elements ********************/
/***************************************************************/
// Instant start = Instant.now();
byte[] digestS = sha1.digest(s.getBytes());
Element sE = pairing.getZr()
.newElementFromHash(digestS, 0, digestS.length)
.getImmutable();
byte[] digestO = sha1.digest(o.getBytes());
Element oE = pairing.getZr()
.newElementFromHash(digestO, 0, digestO.length)
.getImmutable();
if (s.equals("*")) {
result[0] = pairing.getZr().newZeroElement();
result[1] = pairing.getZr().newZeroElement();
} else {
result[0] = pairing.getZr().newOneElement();
result[1] = sE;
}
if (o.equals("*")) {
result[2] = pairing.getZr().newZeroElement();
result[3] = pairing.getZr().newZeroElement();
} else {
result[2] = pairing.getZr().newOneElement();
result[3] = oE;
}
// Duration dur = Duration.between(start, Instant.now());
// System.out.format("SPO Elements generated in: %sms%n",
// dur.toMillis());
/***************************************************************/
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}