code: private void xorPayloadToHmacPad(byte[] workBytes) {
      int payloadSize = workBytes.length - OVERHEAD_SIZE;
      int sections = (payloadSize + COUNTER_PAGESIZE - 1) / COUNTER_PAGESIZE;
      checkArgument(sections <= COUNTER_SECTIONS, "Payload is %s bytes, exceeds limit of %s",
          payloadSize, COUNTER_PAGESIZE * COUNTER_SECTIONS);
  
      Mac encryptionHmac = createMac();
  
      byte[] pad = new byte[COUNTER_PAGESIZE + 3];
      int counterSize = 0;
  
      for (int section = 0; section < sections; ++section) {
        int sectionBase = section * COUNTER_PAGESIZE;
        int sectionSize = min(payloadSize - sectionBase, COUNTER_PAGESIZE);
  
        try {
          encryptionHmac.reset();
          encryptionHmac.init(keys.getEncryptionKey());
          encryptionHmac.update(workBytes, INITV_BASE, INITV_SIZE);
          if (counterSize != 0) {
            encryptionHmac.update(pad, COUNTER_PAGESIZE, counterSize);
          }
          encryptionHmac.doFinal(pad, 0);
        } catch (ShortBufferException | InvalidKeyException e) {
          throw new IllegalStateException(e);
        }
  
        for (int i = 0; i < sectionSize; ++i) {
          workBytes[PAYLOAD_BASE + sectionBase + i] ^= pad[i];
        }
  
        Arrays.fill(pad, 0, COUNTER_PAGESIZE, (byte) 0);
  
        if (counterSize == 0 || ++pad[COUNTER_PAGESIZE + counterSize - 1] == 0) {
          ++counterSize;
        }
      }
    }
docs: {@code payload = payload ^ hmac(encryptionKey, initVector || counterBytes)}
  per max-20-byte blocks.