/** * s2v per https://tools.ietf.org/html/rfc5297 * * @param s * @return s2v(si) * @throws GeneralSecurityException */ private byte[] s2v(final byte[]... s) throws GeneralSecurityException { if (s.length == 0) { // Should never happen with AES-SIV, but we include this for completeness. return cmacForS2V.computeMac(BLOCK_ONE); } byte[] result = cmacForS2V.computeMac(BLOCK_ZERO); for (int i = 0; i < s.length - 1; i++) { result = Bytes.xor(AesUtil.dbl(result), cmacForS2V.computeMac(s[i])); } byte[] lastBlock = s[s.length - 1]; if (lastBlock.length >= 16) { result = Bytes.xorEnd(lastBlock, result); } else { result = Bytes.xor(AesUtil.cmacPad(lastBlock), AesUtil.dbl(result)); } return cmacForS2V.computeMac(result); }