use of com.github.zhenwei.core.crypto.params.ParametersWithUKM in project LinLong-Java by zhenwei1108.
the class GOST28147WrapEngine method init.
public void init(boolean forWrapping, CipherParameters param) {
if (param instanceof ParametersWithRandom) {
ParametersWithRandom pr = (ParametersWithRandom) param;
param = pr.getParameters();
}
ParametersWithUKM pU = (ParametersWithUKM) param;
cipher.init(forWrapping, pU.getParameters());
mac.init(new ParametersWithIV(pU.getParameters(), pU.getUKM()));
}
use of com.github.zhenwei.core.crypto.params.ParametersWithUKM in project LinLong-Java by zhenwei1108.
the class BaseWrapCipher method engineInit.
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
CipherParameters param;
if (key instanceof BCPBEKey) {
BCPBEKey k = (BCPBEKey) key;
if (params instanceof PBEParameterSpec) {
param = Util.makePBEParameters(k, params, wrapEngine.getAlgorithmName());
} else if (k.getParam() != null) {
param = k.getParam();
} else {
throw new InvalidAlgorithmParameterException("PBE requires PBE parameters to be set.");
}
} else {
param = new KeyParameter(key.getEncoded());
}
if (params instanceof IvParameterSpec) {
IvParameterSpec ivSpec = (IvParameterSpec) params;
this.iv = ivSpec.getIV();
param = new ParametersWithIV(param, iv);
}
if (params instanceof GOST28147WrapParameterSpec) {
GOST28147WrapParameterSpec spec = (GOST28147WrapParameterSpec) params;
byte[] sBox = spec.getSBox();
if (sBox != null) {
param = new ParametersWithSBox(param, sBox);
}
param = new ParametersWithUKM(param, spec.getUKM());
}
if (param instanceof KeyParameter && ivSize != 0) {
if (opmode == Cipher.WRAP_MODE || opmode == Cipher.ENCRYPT_MODE) {
iv = new byte[ivSize];
random.nextBytes(iv);
param = new ParametersWithIV(param, iv);
}
}
if (random != null) {
param = new ParametersWithRandom(param, random);
}
try {
switch(opmode) {
case Cipher.WRAP_MODE:
wrapEngine.init(true, param);
this.wrapStream = null;
this.forWrapping = true;
break;
case Cipher.UNWRAP_MODE:
wrapEngine.init(false, param);
this.wrapStream = null;
this.forWrapping = false;
break;
case Cipher.ENCRYPT_MODE:
wrapEngine.init(true, param);
this.wrapStream = new ErasableOutputStream();
this.forWrapping = true;
break;
case Cipher.DECRYPT_MODE:
wrapEngine.init(false, param);
this.wrapStream = new ErasableOutputStream();
this.forWrapping = false;
break;
default:
throw new InvalidParameterException("Unknown mode parameter passed to init.");
}
} catch (Exception e) {
throw new InvalidKeyOrParametersException(e.getMessage(), e);
}
}
use of com.github.zhenwei.core.crypto.params.ParametersWithUKM in project LinLong-Java by zhenwei1108.
the class CryptoProWrapEngine method init.
public void init(boolean forWrapping, CipherParameters param) {
if (param instanceof ParametersWithRandom) {
ParametersWithRandom pr = (ParametersWithRandom) param;
param = pr.getParameters();
}
ParametersWithUKM pU = (ParametersWithUKM) param;
byte[] sBox = null;
KeyParameter kParam;
if (pU.getParameters() instanceof ParametersWithSBox) {
kParam = (KeyParameter) ((ParametersWithSBox) pU.getParameters()).getParameters();
sBox = ((ParametersWithSBox) pU.getParameters()).getSBox();
} else {
kParam = (KeyParameter) pU.getParameters();
}
kParam = new KeyParameter(cryptoProDiversify(kParam.getKey(), pU.getUKM(), sBox));
if (sBox != null) {
super.init(forWrapping, new ParametersWithUKM(new ParametersWithSBox(kParam, sBox), pU.getUKM()));
} else {
super.init(forWrapping, new ParametersWithUKM(kParam, pU.getUKM()));
}
}
use of com.github.zhenwei.core.crypto.params.ParametersWithUKM in project LinLong-Java by zhenwei1108.
the class ECVKOAgreement method init.
public void init(CipherParameters key) {
ParametersWithUKM p = (ParametersWithUKM) key;
this.key = (ECPrivateKeyParameters) p.getParameters();
this.ukm = toInteger(p.getUKM());
}
Aggregations