1 // Copyright 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 //////////////////////////////////////////////////////////////////////////////// 16 17 package com.google.crypto.tink.mac; 18 19 import java.nio.ByteBuffer; 20 import java.security.GeneralSecurityException; 21 22 /** 23 * An interface representing a verification of the Streaming MAC. 24 * 25 * <p>WARNING: Implementations of this interface are not thread-safe, so the caller must ensure 26 * thread-safety if accessing objects implementing this interface concurrently. 27 */ 28 public interface ChunkedMacVerification { 29 30 /** 31 * Processes the next chunk of input, represented by {@code ByteBuffer data}. 32 * In particular, reads the {@code data.remaining()} number of bytes from the provided buffer, 33 * starting at the byte with position {@code data.position()}. 34 * 35 * <p>Updates the inner state of the computation. Requires exclusive access. 36 * 37 * <p>NOTE: arbitrary slicing of data is permitted, i.e. a series of {@code update()}'s with 38 * inputs {@code "ab"}, {@code "cd"}, and {@code "ef"} produces the same result as a series of 39 * inputs {@code "abc"}, {@code "def"}. 40 * 41 * @throws IllegalStateException if called after verifyMac() 42 * @throws GeneralSecurityException when something went wrong with the update 43 */ update(ByteBuffer data)44 void update(ByteBuffer data) throws GeneralSecurityException; 45 46 /** 47 * Verifies that the provided data matches the tag. After this method has been called, the object 48 * can no longer be used. 49 * 50 * <p>Requires exclusive access. 51 * 52 * @throws IllegalStateException when called more than once 53 * @throws GeneralSecurityException when the tag does not match the data 54 */ verifyMac()55 void verifyMac() throws GeneralSecurityException; 56 } 57