use of com.github.zhenwei.core.crypto.params.CramerShoupPrivateKeyParameters in project LinLong-Java by zhenwei1108.
the class CramerShoupKeyPairGenerator method generateKeyPair.
public AsymmetricCipherKeyPair generateKeyPair() {
CramerShoupParameters csParams = param.getParameters();
CramerShoupPrivateKeyParameters sk = generatePrivateKey(param.getRandom(), csParams);
CramerShoupPublicKeyParameters pk = calculatePublicKey(csParams, sk);
sk.setPk(pk);
return new AsymmetricCipherKeyPair(pk, sk);
}
use of com.github.zhenwei.core.crypto.params.CramerShoupPrivateKeyParameters in project LinLong-Java by zhenwei1108.
the class CramerShoupCoreEngine method decryptBlock.
public BigInteger decryptBlock(CramerShoupCiphertext input) throws CramerShoupCiphertextException {
BigInteger result = null;
if (key.isPrivate() && !this.forEncryption && key instanceof CramerShoupPrivateKeyParameters) {
CramerShoupPrivateKeyParameters sk = (CramerShoupPrivateKeyParameters) key;
BigInteger p = sk.getParameters().getP();
Digest digest = sk.getParameters().getH();
byte[] u1Bytes = input.getU1().toByteArray();
digest.update(u1Bytes, 0, u1Bytes.length);
byte[] u2Bytes = input.getU2().toByteArray();
digest.update(u2Bytes, 0, u2Bytes.length);
byte[] eBytes = input.getE().toByteArray();
digest.update(eBytes, 0, eBytes.length);
if (this.label != null) {
byte[] lBytes = this.label;
digest.update(lBytes, 0, lBytes.length);
}
byte[] out = new byte[digest.getDigestSize()];
digest.doFinal(out, 0);
BigInteger a = new BigInteger(1, out);
BigInteger v = input.u1.modPow(sk.getX1().add(sk.getY1().multiply(a)), p).multiply(input.u2.modPow(sk.getX2().add(sk.getY2().multiply(a)), p)).mod(p);
// check correctness of ciphertext
if (input.v.equals(v)) {
result = input.e.multiply(input.u1.modPow(sk.getZ(), p).modInverse(p)).mod(p);
} else {
throw new CramerShoupCiphertextException("Sorry, that ciphertext is not correct");
}
}
return result;
}
use of com.github.zhenwei.core.crypto.params.CramerShoupPrivateKeyParameters in project LinLong-Java by zhenwei1108.
the class CramerShoupKeyPairGenerator method generatePrivateKey.
private CramerShoupPrivateKeyParameters generatePrivateKey(SecureRandom random, CramerShoupParameters csParams) {
BigInteger p = csParams.getP();
CramerShoupPrivateKeyParameters key = new CramerShoupPrivateKeyParameters(csParams, generateRandomElement(p, random), generateRandomElement(p, random), generateRandomElement(p, random), generateRandomElement(p, random), generateRandomElement(p, random));
return key;
}
Aggregations