@BeforeClass
  public static void setUp() throws Exception {
    vanillaImplementationTestVectors =
        new AesGcmHkdfStreamingTestVector[] {
          // Short initial key material.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f",
              /* plaintextSize= */ 20,
              /* chunkSize= */ 64),
          // Ciphertext smaller than one segment.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 0,
              HashType.SHA1,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 20,
              /* chunkSize= */ 64),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 400,
              /* chunkSize= */ 64),
          // Ciphertext smaller than one segment, with a non-zero offset.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA512,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 20,
              /* chunkSize= */ 64),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 8,
              HashType.SHA1,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 400,
              /* chunkSize= */ 64),
          // Empty plaintext.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 0,
              /* chunkSize= */ 128),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA512,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 0,
              /* chunkSize= */ 128),
          // Ciphertext contains more than one segment.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 0,
              HashType.SHA1,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 1024,
              /* chunkSize= */ 128),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 3086,
              /* chunkSize= */ 128),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 32,
              /* ciphertextSegmentSize= */ 1024,
              /* firstSegmentOffset= */ 0,
              HashType.SHA512,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 12345,
              /* chunkSize= */ 128),
          // During decryption large plaintext chunks are requested.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 0,
              HashType.SHA1,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 1024,
              /* chunkSize= */ 4096),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 3086,
              /* chunkSize= */ 4096),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 32,
              /* ciphertextSegmentSize= */ 1024,
              /* firstSegmentOffset= */ 0,
              HashType.SHA512,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 12345,
              /* chunkSize= */ 5000),
          // Same as above but the offset is non-zero.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA1,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 1024,
              /* chunkSize= */ 64),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 20,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 3086,
              /* chunkSize= */ 256),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 32,
              /* ciphertextSegmentSize= */ 1024,
              /* firstSegmentOffset= */ 10,
              HashType.SHA512,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 12345,
              /* chunkSize= */ 5000),
          // The ciphertext ends at a segment boundary.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 0,
              HashType.SHA1,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 216,
              /* chunkSize= */ 64),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 16,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 200,
              /* chunkSize= */ 256),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 16,
              HashType.SHA512,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 440,
              /* chunkSize= */ 1024),
          // During decryption single bytes are requested.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 1024,
              /* chunkSize= */ 1),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 0,
              HashType.SHA512,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 5086,
              /* chunkSize= */ 1)
        };
    // In the following test vectors the chunk sizes are zeroed since they are not needed for the
    // test.
    randomAccessTestVectors =
        new AesGcmHkdfStreamingTestVector[] {
          // The ciphertext is smaller than 1 segment.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 100,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 400,
              /* chunkSize= */ 0),
          // Same as above with an offset.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 20,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 100,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 8,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 400,
              /* chunkSize= */ 0),
          // Empty plaintext.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 0,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 0,
              /* chunkSize= */ 0),
          // Ciphertext contains more than one segment.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 2048,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 4096,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 32,
              /* ciphertextSegmentSize= */ 1024,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 12345,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 4096,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 123456,
              /* chunkSize= */ 0),
          // Same as above but with an offset.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 2048,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 10,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 4096,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 32,
              /* ciphertextSegmentSize= */ 1024,
              /* firstSegmentOffset= */ 20,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 12345,
              /* chunkSize= */ 0),
          // The ciphertext ends at a segment boundary.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 216,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 16,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 200,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 16,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 440,
              /* chunkSize= */ 0),
        };
    singleBytesTestVectors =
        new AesGcmHkdfStreamingTestVector[] {
          // Encrypting with the stream writing single bytes. Chunk size isn't used for this test.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 1024,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 32,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 1024,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 12345,
              /* chunkSize= */ 0),
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 512,
              /* firstSegmentOffset= */ 0,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f00112233445566778899aabbccddeeff",
              /* plaintextSize= */ 111111,
              /* chunkSize= */ 0),
        };
    skipWithStreamTestVectors =
        new AesGcmHkdfStreamingTestVector[] {
          // Smallest chunk size.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f",
              /* plaintextSize= */ 4096,
              /* chunkSize= */ 1),
          // Chunk size < segmentSize.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA1,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f",
              /* plaintextSize= */ 4096,
              /* chunkSize= */ 37),
          // Chunk size > segmentSize.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA512,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f",
              /* plaintextSize= */ 4096,
              /* chunkSize= */ 384),
          // Chunk size > 3*segmentSize.
          new AesGcmHkdfStreamingTestVector(
              /* keySizeInBytes= */ 16,
              /* ciphertextSegmentSize= */ 256,
              /* firstSegmentOffset= */ 8,
              HashType.SHA256,
              /* ikm= */ "000102030405060708090a0b0c0d0e0f",
              /* plaintextSize= */ 4096,
              /* chunkSize= */ 800),
        };
    defaultAesHkdfStreamingInstance =
        new AesGcmHkdfStreaming(
            Hex.decode("000102030405060708090a0b0c0d0e0f"), "HmacSha256", 16, 4096, 0);
  }
Encrypt some plaintext to a file, then decrypt from the file
java_src/src/test/java/com/google/crypto/tink/subtle/AesGcmHkdfStreamingTest.java