Search in sources :

Example 1 with GMac

use of org.bouncycastle.crypto.macs.GMac in project xipki by xipki.

the class EmulatorP11Identity method aesGmac.

// TODO: check the correctness
private byte[] aesGmac(P11Params params, byte[] contentToSign) throws P11TokenException {
    if (params == null) {
        throw new P11TokenException("iv must not be null");
    }
    byte[] iv;
    if (params instanceof P11IVParams) {
        iv = ((P11IVParams) params).getIV();
    } else {
        throw new P11TokenException("params must be instanceof P11IVParams");
    }
    GMac gmac = new GMac(new GCMBlockCipher(new AESEngine()));
    ParametersWithIV paramsWithIv = new ParametersWithIV(new KeyParameter(signingKey.getEncoded()), iv);
    gmac.init(paramsWithIv);
    gmac.update(contentToSign, 0, contentToSign.length);
    byte[] signature = new byte[gmac.getMacSize()];
    gmac.doFinal(signature, 0);
    return signature;
}
Also used : ParametersWithIV(org.bouncycastle.crypto.params.ParametersWithIV) AESEngine(org.bouncycastle.crypto.engines.AESEngine) P11TokenException(org.xipki.security.exception.P11TokenException) KeyParameter(org.bouncycastle.crypto.params.KeyParameter) GMac(org.bouncycastle.crypto.macs.GMac) GCMBlockCipher(org.bouncycastle.crypto.modes.GCMBlockCipher) P11IVParams(org.xipki.security.pkcs11.P11IVParams)

Aggregations

AESEngine (org.bouncycastle.crypto.engines.AESEngine)1 GMac (org.bouncycastle.crypto.macs.GMac)1 GCMBlockCipher (org.bouncycastle.crypto.modes.GCMBlockCipher)1 KeyParameter (org.bouncycastle.crypto.params.KeyParameter)1 ParametersWithIV (org.bouncycastle.crypto.params.ParametersWithIV)1 P11TokenException (org.xipki.security.exception.P11TokenException)1 P11IVParams (org.xipki.security.pkcs11.P11IVParams)1