use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.
the class RSAPSSAlgorithmParameters method populateFromSpec.
private void populateFromSpec() {
if (spec == null || hashAlg == null) {
return;
}
String hashAlgName = spec.getDigestAlgorithm();
String maskGenName = spec.getMGFAlgorithm();
int saltLen = spec.getSaltLength();
this.saltLen = new BigInt(saltLen);
int trailer = spec.getTrailerField();
// Create the hash alg and mask gen func objects
if (hashAlgName.equals("SHA-256")) {
hashAlg = new AlgorithmId(AlgorithmId.SHA256_oid);
} else if (hashAlgName.equals("SHA-512")) {
hashAlg = new AlgorithmId(AlgorithmId.SHA512_oid);
} else if (hashAlgName.equals("SHA-384")) {
hashAlg = new AlgorithmId(AlgorithmId.SHA384_oid);
} else {
// Default to SHA-1 per above ASN.1 encoding.
hashAlg = new AlgorithmId(AlgorithmId.SHA_oid);
}
}
use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.
the class RSAPSSAlgorithmParameters method decode.
private void decode(DerInputStream in, byte[] encoded) throws IOException {
if (in == null) {
throw new IOException("Invalid input: got null DerInputStream");
}
// Sequence has 3 members, trailer field ignored
DerValue[] seq = in.getSequence(3);
if (seq.length < 3 || seq.length > 4) {
throw new IOException("Invalid data! Expected a sequence with either 3 or 4 members; got " + seq.length);
}
if (seq[0].isContextSpecific((byte) 0)) {
seq[0] = seq[0].data.getDerValue();
} else {
throw new IOException("Invalid encoded data! Expecting OAEP-PSSDigestAlgorithms (hashAlgorithm).");
}
AlgorithmId algid = AlgorithmId.parse(seq[0]);
String specAlgName = getSpecAlgName(algid.getName());
String specMGF1Name = "";
// Now the MFG1 parameter hash fun is the same as the main hash func.
MGF1ParameterSpec specMFG1ParamSpec = new MGF1ParameterSpec(specAlgName);
if (seq[1].isContextSpecific((byte) 1)) {
seq[1] = seq[1].data.getDerValue();
} else {
throw new IOException("Invalid encoded data! Expecting OAEP-PSSDigestAlgorithms (maskGenAlgorithm).");
}
DerInputStream mgf1Str = new DerInputStream(seq[1].toByteArray());
DerValue[] seqMgf1 = mgf1Str.getSequence(2);
ObjectIdentifier mgf1OID = seqMgf1[0].getOID();
if (!mgf1OID.equals(AlgorithmId.MGF1_oid)) {
throw new IOException("Invalid encoded data: expected MGF1 OID but got: " + mgf1OID.toString());
} else {
specMGF1Name = "MGF1";
}
if (seq[2].isContextSpecific((byte) 2)) {
seq[2] = seq[2].data.getDerValue();
} else {
throw new IOException("Invalid encoded data! Expected INTEGER (saltLength).");
}
BigInt sLength = seq[2].getInteger();
this.spec = new PSSParameterSpec(specAlgName, specMGF1Name, specMFG1ParamSpec, sLength.toInt(), 1);
populateFromSpec();
}
Aggregations