@Override
  public void update(ByteBuffer data) throws GeneralSecurityException {
    if (finalized) {
      throw new IllegalStateException(
          "Can not update after computing the MAC tag. Please create a new object.");
    }

    if (localStash.remaining() != AesUtil.BLOCK_SIZE) {
      // Only copy data into the stash if there are existing leftovers.
      int bytesToCopy = min(localStash.remaining(), data.remaining());
      for (int i = 0; i < bytesToCopy; i++) {
        localStash.put(data.get());
      }
    }
    if (localStash.remaining() == 0 && data.remaining() > 0) {
      // Stash is full but there is more data.
      localStash.rewind();
      munch(localStash);
      localStash.rewind();
    }

    // Now, "stash is empty" OR "data is empty".

    // Now process directly from the rest of the input buffer.
    // NOTE: if there are exactly block_size bytes left, don't process yet. (may be last block)
    while (data.remaining() > AesUtil.BLOCK_SIZE) {
      munch(data);
    }

    // There is now {0 .. block size} data left,
    // stash is empty with the block size capacity
    // => we can safely stuff everything into stash.
    localStash.put(data);
  }
We need this AES-block sized buffer in order to account for the possibility of data not
arriving in perfect blocks, and also because we never know which block is going to be the last,
so we need to cache some data unprocessed between calls to update().

Invariant: between calls we have: 0 <= localStash.position < 16, and localStash is a suffix of
data so far, such that the rest is divisible by 16.
java_src/src/main/java/com/google/crypto/tink/mac/internal/ChunkedAesCmacComputation.java