use of org.xipki.security.HashAlgo in project xipki by xipki.
the class AlgorithmUtil method getHashOutputSizeInOctets.
// method getHashAlg
public static int getHashOutputSizeInOctets(ASN1ObjectIdentifier hashAlgo) throws NoSuchAlgorithmException {
ParamUtil.requireNonNull("hashAlgo", hashAlgo);
HashAlgo hashAlgoType = HashAlgo.getInstance(hashAlgo);
if (hashAlgoType == null) {
throw new NoSuchAlgorithmException("Unsupported hash algorithm " + hashAlgo.getId());
}
return hashAlgoType.getLength();
}
use of org.xipki.security.HashAlgo in project xipki by xipki.
the class EmulatorP11Identity method rsaPkcsPssSign.
private byte[] rsaPkcsPssSign(P11Params parameters, byte[] contentToSign, HashAlgo hashAlgo) throws P11TokenException {
if (!(parameters instanceof P11RSAPkcsPssParams)) {
throw new P11TokenException("the parameters is not of " + P11RSAPkcsPssParams.class.getName());
}
P11RSAPkcsPssParams pssParam = (P11RSAPkcsPssParams) parameters;
HashAlgo contentHash = HashAlgo.getInstanceForPkcs11HashMech(pssParam.getHashAlgorithm());
if (contentHash == null) {
throw new P11TokenException("unsupported HashAlgorithm " + pssParam.getHashAlgorithm());
} else if (hashAlgo != null && contentHash != hashAlgo) {
throw new P11TokenException("Invalid parameters: invalid hash algorithm");
}
HashAlgo mgfHash = HashAlgo.getInstanceForPkcs11MgfMech(pssParam.getMaskGenerationFunction());
if (mgfHash == null) {
throw new P11TokenException("unsupported MaskGenerationFunction " + pssParam.getHashAlgorithm());
}
byte[] hashValue = (hashAlgo == null) ? contentToSign : hashAlgo.hash(contentToSign);
byte[] encodedHashValue;
try {
encodedHashValue = SignerUtil.EMSA_PSS_ENCODE(contentHash, hashValue, mgfHash, (int) pssParam.getSaltLength(), getSignatureKeyBitLength(), random);
} catch (XiSecurityException ex) {
throw new P11TokenException("XiSecurityException: " + ex.getMessage(), ex);
}
return rsaX509Sign(encodedHashValue);
}
Aggregations