use of com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams in project jmulticard by ctt-gob-es.
the class OperatorHelper method notDefaultPSSParams.
// for our purposes default includes varient digest with salt the same size as digest
private boolean notDefaultPSSParams(ASN1Sequence seq) throws GeneralSecurityException {
if (seq == null || seq.size() == 0) {
return false;
}
RSASSAPSSparams pssParams = RSASSAPSSparams.getInstance(seq);
if (!pssParams.getMaskGenAlgorithm().getAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1)) {
return true;
}
// same digest for sig and MGF1
if (!pssParams.getHashAlgorithm().equals(AlgorithmIdentifier.getInstance(pssParams.getMaskGenAlgorithm().getParameters()))) {
return true;
}
MessageDigest digest = createDigest(pssParams.getHashAlgorithm());
return pssParams.getSaltLength().intValue() != digest.getDigestLength();
}
use of com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams in project jmulticard by ctt-gob-es.
the class DefaultSignatureNameFinder method getAlgorithmName.
/**
* Return the signature name for the passed in algorithm identifier. For signatures
* that require parameters, like RSASSA-PSS, this is the best one to use.
*
* @param algorithmIdentifier the AlgorithmIdentifier of interest.
* @return a string representation of the name.
*/
public String getAlgorithmName(AlgorithmIdentifier algorithmIdentifier) {
ASN1Encodable params = algorithmIdentifier.getParameters();
if (params != null && !DERNull.INSTANCE.equals(params)) {
if (algorithmIdentifier.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) {
RSASSAPSSparams rsaParams = RSASSAPSSparams.getInstance(params);
AlgorithmIdentifier mgfAlg = rsaParams.getMaskGenAlgorithm();
if (mgfAlg.getAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1)) {
AlgorithmIdentifier digAlg = rsaParams.getHashAlgorithm();
ASN1ObjectIdentifier mgfHashOid = AlgorithmIdentifier.getInstance(mgfAlg.getParameters()).getAlgorithm();
if (mgfHashOid.equals(digAlg.getAlgorithm())) {
return getDigestName(digAlg.getAlgorithm()) + "WITHRSAANDMGF1";
} else {
return getDigestName(digAlg.getAlgorithm()) + "WITHRSAANDMGF1USING" + getDigestName(mgfHashOid);
}
}
return getDigestName(rsaParams.getHashAlgorithm().getAlgorithm()) + "WITHRSAAND" + mgfAlg.getAlgorithm().getId();
}
}
if (oids.containsKey(algorithmIdentifier.getAlgorithm())) {
return (String) oids.get(algorithmIdentifier.getAlgorithm());
}
return algorithmIdentifier.getAlgorithm().getId();
}
use of com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams in project LinLong-Java by zhenwei1108.
the class OperatorHelper method notDefaultPSSParams.
// for our purposes default includes varient digest with salt the same size as digest
private boolean notDefaultPSSParams(ASN1Sequence seq) throws GeneralSecurityException {
if (seq == null || seq.size() == 0) {
return false;
}
RSASSAPSSparams pssParams = RSASSAPSSparams.getInstance(seq);
if (!pssParams.getMaskGenAlgorithm().getAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1)) {
return true;
}
// same digest for sig and MGF1
if (!pssParams.getHashAlgorithm().equals(AlgorithmIdentifier.getInstance(pssParams.getMaskGenAlgorithm().getParameters()))) {
return true;
}
MessageDigest digest = createDigest(pssParams.getHashAlgorithm());
return pssParams.getSaltLength().intValue() != digest.getDigestLength();
}
use of com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams in project LinLong-Java by zhenwei1108.
the class JcaContentSignerBuilder method createPSSParams.
private static RSASSAPSSparams createPSSParams(PSSParameterSpec pssSpec) {
DigestAlgorithmIdentifierFinder digFinder = new DefaultDigestAlgorithmIdentifierFinder();
AlgorithmIdentifier digId = digFinder.find(pssSpec.getDigestAlgorithm());
if (digId.getParameters() == null) {
digId = new AlgorithmIdentifier(digId.getAlgorithm(), DERNull.INSTANCE);
}
AlgorithmIdentifier mgfDig = digFinder.find(((MGF1ParameterSpec) pssSpec.getMGFParameters()).getDigestAlgorithm());
if (mgfDig.getParameters() == null) {
mgfDig = new AlgorithmIdentifier(mgfDig.getAlgorithm(), DERNull.INSTANCE);
}
return new RSASSAPSSparams(digId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, mgfDig), new ASN1Integer(pssSpec.getSaltLength()), new ASN1Integer(pssSpec.getTrailerField()));
}
use of com.github.zhenwei.core.asn1.pkcs.RSASSAPSSparams in project xipki by xipki.
the class ResponderSigner method getSignatureAlgorithmName.
private static String getSignatureAlgorithmName(AlgorithmIdentifier sigAlgId) {
ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm();
if (!PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
return algOid.getId();
}
ASN1Encodable asn1Encodable = sigAlgId.getParameters();
RSASSAPSSparams param = RSASSAPSSparams.getInstance(asn1Encodable);
ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm();
return digestAlgOid.getId() + "WITHRSAANDMGF1";
}
Aggregations