Search in sources :

Example 1 with CK_RSA_PKCS_PSS_PARAMS

use of org.openecard.mdlw.sal.cryptoki.CK_RSA_PKCS_PSS_PARAMS in project open-ecard by ecsec.

the class MwPrivateKey method sign.

/**
 * Signs Data with a {@link Mechanism}.
 * Returns the signed Data in an byte array.
 *
 * @param mechanism
 * @param data
 * @return
 * @throws CryptokiException
 */
public byte[] sign(long mechanism, byte[] data) throws CryptokiException {
    Pointer paramsPtr;
    NativeLong paramsPtrSize;
    if (isPSSAlg((int) mechanism)) {
        // only execute with PSS algorithm
        // determine parameters for PKCS#11 PSS
        LOG.debug("Preparing PSS Parameters.");
        NativeLong hashAlg = new NativeLong(getHashAlg((int) mechanism, data), true);
        NativeLong mgfAlg = new NativeLong(getMgf1Alg(hashAlg.intValue()), true);
        NativeLong sLen = new NativeLong(getHashLen(hashAlg.intValue()), true);
        CK_RSA_PKCS_PSS_PARAMS pssParams = new CK_RSA_PKCS_PSS_PARAMS(hashAlg, mgfAlg, sLen);
        pssParams.write();
        paramsPtr = pssParams.getPointer();
        paramsPtrSize = new NativeLong(pssParams.size(), true);
    } else {
        paramsPtr = Pointer.NULL;
        paramsPtrSize = new NativeLong(0, true);
    }
    CK_MECHANISM pMechanism = new CK_MECHANISM(new NativeLong(mechanism, true), paramsPtr, paramsPtrSize);
    try (MiddleWareWrapper.LockedMiddlewareWrapper lmw = mw.lock()) {
        lmw.signInit(session.getSessionId(), pMechanism, objectHandle);
        return lmw.sign(session.getSessionId(), data);
    } catch (InterruptedException ex) {
        throw new ThreadTerminateException("Thread interrupted while waiting for Middleware lock.", ex);
    }
}
Also used : CK_RSA_PKCS_PSS_PARAMS(org.openecard.mdlw.sal.cryptoki.CK_RSA_PKCS_PSS_PARAMS) NativeLong(com.sun.jna.NativeLong) Pointer(com.sun.jna.Pointer) ThreadTerminateException(org.openecard.common.ThreadTerminateException) CK_MECHANISM(org.openecard.mdlw.sal.cryptoki.CK_MECHANISM)

Aggregations

NativeLong (com.sun.jna.NativeLong)1 Pointer (com.sun.jna.Pointer)1 ThreadTerminateException (org.openecard.common.ThreadTerminateException)1 CK_MECHANISM (org.openecard.mdlw.sal.cryptoki.CK_MECHANISM)1 CK_RSA_PKCS_PSS_PARAMS (org.openecard.mdlw.sal.cryptoki.CK_RSA_PKCS_PSS_PARAMS)1