public static int getHashOutputSizeInOctets(final ASN1ObjectIdentifier hashAlgo) throws NoSuchAlgorithmException { ParamUtil.requireNonNull("hashAlgo", hashAlgo); HashAlgoType hashAlgoType = HashAlgoType.getHashAlgoType(hashAlgo); if (hashAlgoType == null) { throw new NoSuchAlgorithmException("Unsupported hash algorithm " + hashAlgo.getId()); } return hashAlgoType.length(); } // method getHashOutputSizeInOctets
final SecureRandom random) throws XiSecurityException { final int hLen = contentDigest.length(); final byte[] salt = new byte[saltLen]; final byte[] mDash = new byte[8 + saltLen + hLen];
/** * mask generator function, as described in PKCS1v2. */ private static byte[] maskGeneratorFunction1(final HashAlgoType mgfDigest, final byte[] Z, // CHECKSTYLE:SKIP final int length) { int mgfhLen = mgfDigest.length(); byte[] mask = new byte[length]; int counter = 0; byte[] all = new byte[Z.length + 4]; System.arraycopy(Z, 0, all, 0, Z.length); while (counter < (length / mgfhLen)) { ItoOSP(counter, all, Z.length); byte[] hashBuf = mgfDigest.hash(all); System.arraycopy(hashBuf, 0, mask, counter * mgfhLen, mgfhLen); counter++; } if ((counter * mgfhLen) < length) { ItoOSP(counter, all, Z.length); byte[] hashBuf = mgfDigest.hash(all); int offset = counter * mgfhLen; System.arraycopy(hashBuf, 0, mask, offset, mask.length - offset); } return mask; }
public static byte[] EMSA_PKCS1_v1_5_encoding(final byte[] hashValue, final int modulusBigLength, final HashAlgoType hashAlgo) throws XiSecurityException { ParamUtil.requireNonNull("hashValue", hashValue); ParamUtil.requireNonNull("hashAlgo", hashAlgo); final int hashLen = hashAlgo.length(); ParamUtil.requireRange("hashValue.length", hashValue.length, hashLen, hashLen); int blockSize = (modulusBigLength + 7) / 8; byte[] prefix = digestPkcsPrefix.get(hashAlgo); if (prefix.length + hashLen + 3 > blockSize) { throw new XiSecurityException("data too long (maximal " + (blockSize - 3) + " allowed): " + (prefix.length + hashLen)); } byte[] block = new byte[blockSize]; block[0] = 0x00; // type code 1 block[1] = 0x01; int offset = 2; while (offset < block.length - prefix.length - hashLen - 1) { block[offset++] = (byte) 0xFF; } // mark the end of the padding block[offset++] = 0x00; System.arraycopy(prefix, 0, block, offset, prefix.length); offset += prefix.length; System.arraycopy(hashValue, 0, block, offset, hashValue.length); return block; }
public IssuerHash(final HashAlgoType hashAlgo, final byte[] issuerNameHash, final byte[] issuerKeyHash) { this.hashAlgo = ParamUtil.requireNonNull("hashAlgo", hashAlgo); this.issuerNameHash = ParamUtil.requireNonNull("issuerNameHash", issuerNameHash); this.issuerKeyHash = ParamUtil.requireNonNull("issuerKeyHash", issuerKeyHash); final int len = hashAlgo.length(); ParamUtil.requireRange("issuerNameHash.length", issuerNameHash.length, len, len); ParamUtil.requireRange("issuerKeyHash.length", issuerKeyHash.length, len, len); }
public static RSASSAPSSparams createPSSRSAParams(final HashAlgoType digestAlg) throws NoSuchAlgorithmException { ParamUtil.requireNonNull("digestAlg", digestAlg); int saltSize = digestAlg.length(); AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlg.oid(), DERNull.INSTANCE); return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId), new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD); } // method createPSSRSAParams