use of org.bouncycastle.pqc.crypto.sphincsplus.SPHINCSPlusParameters in project jmulticard by ctt-gob-es.
the class PrivateKeyFactory method createKey.
/**
* Create a private key parameter from the passed in PKCS8 PrivateKeyInfo object.
*
* @param keyInfo the PrivateKeyInfo object containing the key material
* @return a suitable private key parameter
* @throws IOException on an error decoding the key
*/
public static AsymmetricKeyParameter createKey(final PrivateKeyInfo keyInfo) throws IOException {
final AlgorithmIdentifier algId = keyInfo.getPrivateKeyAlgorithm();
final ASN1ObjectIdentifier algOID = algId.getAlgorithm();
if (algOID.on(BCObjectIdentifiers.qTESLA)) {
final ASN1OctetString qTESLAPriv = ASN1OctetString.getInstance(keyInfo.parsePrivateKey());
return new QTESLAPrivateKeyParameters(Utils.qTeslaLookupSecurityCategory(keyInfo.getPrivateKeyAlgorithm()), qTESLAPriv.getOctets());
}
if (algOID.equals(BCObjectIdentifiers.sphincs256)) {
return new SPHINCSPrivateKeyParameters(ASN1OctetString.getInstance(keyInfo.parsePrivateKey()).getOctets(), Utils.sphincs256LookupTreeAlgName(SPHINCS256KeyParams.getInstance(keyInfo.getPrivateKeyAlgorithm().getParameters())));
}
if (algOID.equals(BCObjectIdentifiers.newHope)) {
return new NHPrivateKeyParameters(convert(ASN1OctetString.getInstance(keyInfo.parsePrivateKey()).getOctets()));
}
if (algOID.equals(PKCSObjectIdentifiers.id_alg_hss_lms_hashsig)) {
final byte[] keyEnc = ASN1OctetString.getInstance(keyInfo.parsePrivateKey()).getOctets();
final ASN1BitString pubKey = keyInfo.getPublicKeyData();
if (Pack.bigEndianToInt(keyEnc, 0) == 1) {
if (pubKey != null) {
final byte[] pubEnc = pubKey.getOctets();
return LMSPrivateKeyParameters.getInstance(Arrays.copyOfRange(keyEnc, 4, keyEnc.length), Arrays.copyOfRange(pubEnc, 4, pubEnc.length));
}
return LMSPrivateKeyParameters.getInstance(Arrays.copyOfRange(keyEnc, 4, keyEnc.length));
}
if (pubKey != null) {
final byte[] pubEnc = pubKey.getOctets();
return HSSPrivateKeyParameters.getInstance(Arrays.copyOfRange(keyEnc, 4, keyEnc.length), pubEnc);
}
return HSSPrivateKeyParameters.getInstance(Arrays.copyOfRange(keyEnc, 4, keyEnc.length));
}
if (algOID.on(BCObjectIdentifiers.sphincsPlus)) {
final byte[] keyEnc = ASN1OctetString.getInstance(keyInfo.parsePrivateKey()).getOctets();
final SPHINCSPlusParameters spParams = SPHINCSPlusParameters.getParams(Integers.valueOf(Pack.bigEndianToInt(keyEnc, 0)));
return new SPHINCSPlusPrivateKeyParameters(spParams, Arrays.copyOfRange(keyEnc, 4, keyEnc.length));
}
if (algOID.on(BCObjectIdentifiers.pqc_kem_mceliece)) {
final CMCEPrivateKey cmceKey = CMCEPrivateKey.getInstance(keyInfo.parsePrivateKey());
final CMCEParameters spParams = Utils.mcElieceParamsLookup(keyInfo.getPrivateKeyAlgorithm().getAlgorithm());
return new CMCEPrivateKeyParameters(spParams, cmceKey.getDelta(), cmceKey.getC(), cmceKey.getG(), cmceKey.getAlpha(), cmceKey.getS());
} else if (algOID.on(BCObjectIdentifiers.pqc_kem_frodo)) {
final byte[] keyEnc = ASN1OctetString.getInstance(keyInfo.parsePrivateKey()).getOctets();
final FrodoParameters spParams = Utils.frodoParamsLookup(keyInfo.getPrivateKeyAlgorithm().getAlgorithm());
return new FrodoPrivateKeyParameters(spParams, keyEnc);
} else if (algOID.on(BCObjectIdentifiers.pqc_kem_saber)) {
final byte[] keyEnc = ASN1OctetString.getInstance(keyInfo.parsePrivateKey()).getOctets();
final SABERParameters spParams = Utils.saberParamsLookup(keyInfo.getPrivateKeyAlgorithm().getAlgorithm());
return new SABERPrivateKeyParameters(spParams, keyEnc);
} else if (algOID.equals(BCObjectIdentifiers.xmss) || algOID.equals(PQCObjectIdentifiers.xmss_mt)) {
// $NON-NLS-1$
throw new IOException("Modificacion para JMultiCard");
} else if (algOID.equals(PQCObjectIdentifiers.mcElieceCca2)) {
final McElieceCCA2PrivateKey mKey = McElieceCCA2PrivateKey.getInstance(keyInfo.parsePrivateKey());
return new McElieceCCA2PrivateKeyParameters(mKey.getN(), mKey.getK(), mKey.getField(), mKey.getGoppaPoly(), mKey.getP(), Utils.getDigestName(mKey.getDigest().getAlgorithm()));
} else {
// $NON-NLS-1$
throw new RuntimeException("algorithm identifier in private key not recognised");
}
}
use of org.bouncycastle.pqc.crypto.sphincsplus.SPHINCSPlusParameters in project jmulticard by ctt-gob-es.
the class SPHINCSPlusKeyPairGeneratorSpi method initialize.
public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
if (!(params instanceof SPHINCSPlusParameterSpec)) {
throw new InvalidAlgorithmParameterException("parameter object not a CMCEParameterSpec");
}
param = new SPHINCSPlusKeyGenerationParameters(random, (SPHINCSPlusParameters) parameters.get(getNameFromParams(params)));
engine.init(param);
initialised = true;
}
Aggregations