Example usage for org.bouncycastle.asn1.pkcs RSASSAPSSparams DEFAULT_TRAILER_FIELD

List of usage examples for org.bouncycastle.asn1.pkcs RSASSAPSSparams DEFAULT_TRAILER_FIELD

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.pkcs RSASSAPSSparams DEFAULT_TRAILER_FIELD.

Prototype

ASN1Integer DEFAULT_TRAILER_FIELD

To view the source code for org.bouncycastle.asn1.pkcs RSASSAPSSparams DEFAULT_TRAILER_FIELD.

Click Source Link

Usage

From source file:org.xipki.common.util.AlgorithmUtil.java

License:Open Source License

static public RSASSAPSSparams createPSSRSAParams(final ASN1ObjectIdentifier digestAlgOID)
        throws NoSuchAlgorithmException {
    int saltSize;
    if (X509ObjectIdentifiers.id_SHA1.equals(digestAlgOID)) {
        saltSize = 20;/*w  w  w  .  j  a  v a  2 s  .c  o m*/
    } else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOID)) {
        saltSize = 28;
    } else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOID)) {
        saltSize = 32;
    } else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOID)) {
        saltSize = 48;
    } else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOID)) {
        saltSize = 64;
    } else {
        throw new NoSuchAlgorithmException("unknown digest algorithm " + digestAlgOID);
    }

    AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlgOID, DERNull.INSTANCE);
    return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId),
            new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD);
}

From source file:org.xipki.commons.security.pkcs11.P11RSAPkcsPssParams.java

License:Open Source License

public P11RSAPkcsPssParams(final RSASSAPSSparams asn1Params) {
    ASN1ObjectIdentifier asn1Oid = asn1Params.getHashAlgorithm().getAlgorithm();
    HashAlgoType contentHashAlgo = HashAlgoType.getHashAlgoType(asn1Oid);
    if (contentHashAlgo == null) {
        throw new IllegalArgumentException("unsupported hash algorithm " + asn1Oid.getId());
    }/*  w w w .  j ava  2  s. c om*/

    AlgorithmIdentifier mga = asn1Params.getMaskGenAlgorithm();
    asn1Oid = mga.getAlgorithm();
    if (!PKCSObjectIdentifiers.id_mgf1.equals(asn1Oid)) {
        throw new IllegalArgumentException("unsupported MGF algorithm " + asn1Oid.getId());
    }

    asn1Oid = AlgorithmIdentifier.getInstance(mga.getParameters()).getAlgorithm();
    HashAlgoType mgfHashAlgo = HashAlgoType.getHashAlgoType(asn1Oid);
    if (mgfHashAlgo == null) {
        throw new IllegalArgumentException("unsupported MGF hash algorithm " + asn1Oid.getId());
    }
    this.saltLength = asn1Params.getSaltLength().longValue();
    BigInteger trailerField = asn1Params.getTrailerField();
    if (!RSASSAPSSparams.DEFAULT_TRAILER_FIELD.getValue().equals(trailerField)) {
        throw new IllegalArgumentException("unsupported trailerField " + trailerField);
    }

    switch (contentHashAlgo) {
    case SHA1:
        this.hashAlgorithm = P11Constants.CKM_SHA_1;
        break;
    case SHA224:
        this.hashAlgorithm = P11Constants.CKM_SHA224;
        break;
    case SHA256:
        this.hashAlgorithm = P11Constants.CKM_SHA256;
        break;
    case SHA384:
        this.hashAlgorithm = P11Constants.CKM_SHA384;
        break;
    case SHA512:
        this.hashAlgorithm = P11Constants.CKM_SHA512;
        break;
    case SHA3_224:
        this.hashAlgorithm = P11Constants.CKM_SHA3_224;
        break;
    case SHA3_256:
        this.hashAlgorithm = P11Constants.CKM_SHA3_256;
        break;
    case SHA3_384:
        this.hashAlgorithm = P11Constants.CKM_SHA3_384;
        break;
    case SHA3_512:
        this.hashAlgorithm = P11Constants.CKM_SHA3_512;
        break;
    default:
        throw new RuntimeException("should not reach here");
    }

    switch (mgfHashAlgo) {
    case SHA1:
        this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA1;
        break;
    case SHA224:
        this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA224;
        break;
    case SHA256:
        this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA256;
        break;
    case SHA384:
        this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA384;
        break;
    case SHA512:
        this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA512;
        break;
    case SHA3_224:
        this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA3_224;
        break;
    case SHA3_256:
        this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA3_256;
        break;
    case SHA3_384:
        this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA3_384;
        break;
    case SHA3_512:
        this.maskGenerationFunction = P11Constants.CKG_MGF1_SHA3_512;
        break;
    default:
        throw new RuntimeException("should not reach here");
    }
}

From source file:org.xipki.commons.security.util.AlgorithmUtil.java

License:Open Source License

public static RSASSAPSSparams createPSSRSAParams(final HashAlgoType digestAlg) throws NoSuchAlgorithmException {
    ParamUtil.requireNonNull("digestAlg", digestAlg);
    int saltSize = digestAlg.getLength();
    AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlg.getOid(), DERNull.INSTANCE);
    return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId),
            new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD);
}

From source file:org.xipki.ocsp.client.api.RequestOptions.java

License:Open Source License

static public RSASSAPSSparams createPSSRSAParams(final ASN1ObjectIdentifier digestAlgOID) {
    int saltSize;
    if (X509ObjectIdentifiers.id_SHA1.equals(digestAlgOID)) {
        saltSize = 20;//from w w  w. ja  v  a2s  .c o  m
    } else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOID)) {
        saltSize = 28;
    } else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOID)) {
        saltSize = 32;
    } else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOID)) {
        saltSize = 48;
    } else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOID)) {
        saltSize = 64;
    } else {
        throw new RuntimeException("unknown digest algorithm " + digestAlgOID);
    }

    AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlgOID, DERNull.INSTANCE);
    return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId),
            new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD);
}

From source file:org.xipki.pki.ocsp.client.api.RequestOptions.java

License:Open Source License

public static RSASSAPSSparams createPSSRSAParams(final ASN1ObjectIdentifier digestAlgOid) {
    int saltSize;
    if (X509ObjectIdentifiers.id_SHA1.equals(digestAlgOid)) {
        saltSize = 20;/*  w w  w  . j  a va2s  .c  o m*/
    } else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOid)) {
        saltSize = 28;
    } else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOid)) {
        saltSize = 32;
    } else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOid)) {
        saltSize = 48;
    } else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOid)) {
        saltSize = 64;
    } else {
        throw new RuntimeException("unknown digest algorithm " + digestAlgOid);
    }

    AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlgOid, DERNull.INSTANCE);
    return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId),
            new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD);
}