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;
}
Aggregations