test_class.declarator: keySizeInBytes
test_class.modifier: private
test_class.original_string: private Integer[] keySizeInBytes;
test_class.type: Integer[]
test_class.var_name: keySizeInBytes
test_class.file: java_src/src/test/java/com/google/crypto/tink/aead/subtle/AesGcmSivTest.java
test_class.identifier: AesGcmSivTest
test_case.body: @Test
    public void testWycheproofVectors() throws Exception {
      JSONObject json =
          WycheproofTestUtil.readJson("../wycheproof/testvectors/aes_gcm_siv_test.json");
      int errors = 0;
      int cntSkippedTests = 0;
      JSONArray testGroups = json.getJSONArray("testGroups");
      for (int i = 0; i < testGroups.length(); i++) {
        JSONObject group = testGroups.getJSONObject(i);
        int keySize = group.getInt("keySize");
        JSONArray tests = group.getJSONArray("tests");
        if (!Arrays.asList(keySizeInBytes).contains(keySize / 8)) {
          cntSkippedTests += tests.length();
          continue;
        }
        for (int j = 0; j < tests.length(); j++) {
          JSONObject testcase = tests.getJSONObject(j);
          String tcId =
              String.format(
                  "testcase %d (%s)", testcase.getInt("tcId"), testcase.getString("comment"));
          byte[] iv = Hex.decode(testcase.getString("iv"));
          byte[] key = Hex.decode(testcase.getString("key"));
          byte[] msg = Hex.decode(testcase.getString("msg"));
          byte[] aad = Hex.decode(testcase.getString("aad"));
          byte[] ct = Hex.decode(testcase.getString("ct"));
          byte[] tag = Hex.decode(testcase.getString("tag"));
          byte[] ciphertext = Bytes.concat(iv, ct, tag);
          // Result is one of "valid", "invalid", "acceptable".
          // "valid" are test vectors with matching plaintext, ciphertext and tag.
          // "invalid" are test vectors with invalid parameters or invalid ciphertext and tag.
          // "acceptable" are test vectors with weak parameters or legacy formats.
          String result = testcase.getString("result");
          // Tink only supports 12-byte iv.
          if (iv.length != 12) {
            result = "invalid";
          }
  
          try {
            AesGcmSiv gcm = new AesGcmSiv(key);
            byte[] decrypted = gcm.decrypt(ciphertext, aad);
            boolean eq = TestUtil.arrayEquals(decrypted, msg);
            if (result.equals("invalid")) {
              System.out.printf(
                  "FAIL %s: accepting invalid ciphertext, cleartext: %s, decrypted: %s%n",
                  tcId, Hex.encode(msg), Hex.encode(decrypted));
              errors++;
            } else {
              if (!eq) {
                System.out.printf(
                    "FAIL %s: incorrect decryption, result: %s, expected: %s%n",
                    tcId, Hex.encode(decrypted), Hex.encode(msg));
                errors++;
              }
            }
          } catch (GeneralSecurityException ex) {
            if (result.equals("valid")) {
              System.out.printf("FAIL %s: cannot decrypt, exception %s%n", tcId, ex);
              errors++;
            }
          }
        }
      }
      System.out.printf("Number of tests skipped: %d", cntSkippedTests);
      assertEquals(0, errors);
    }
test_case.class_method_signature: AesGcmSivTest.testWycheproofVectors()
test_case.full_signature: @Test public void testWycheproofVectors()
test_case.identifier: testWycheproofVectors
test_case.invocations: readJson getJSONArray length getJSONObject getInt getJSONArray contains asList length length getJSONObject format getInt getString decode getString decode getString decode getString decode getString decode getString decode getString concat getString decrypt arrayEquals equals printf encode encode printf encode encode equals printf printf assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testWycheproofVectors()
focal_class.declarator: localCipher =
        new ThreadLocal<Cipher>() {
          @Override
          protected Cipher initialValue() {
            try {
              return EngineFactory.CIPHER.getInstance("AES/GCM-SIV/NoPadding");
            } catch (GeneralSecurityException ex) {
              throw new IllegalStateException(ex);
            }
          }
        }
focal_class.modifier: private static final
focal_class.original_string: private static final ThreadLocal<Cipher> localCipher =
        new ThreadLocal<Cipher>() {
          @Override
          protected Cipher initialValue() {
            try {
              return EngineFactory.CIPHER.getInstance("AES/GCM-SIV/NoPadding");
            } catch (GeneralSecurityException ex) {
              throw new IllegalStateException(ex);
            }
          }
        };
focal_class.type: ThreadLocal<Cipher>
focal_class.var_name: localCipher
focal_class.declarator: IV_SIZE_IN_BYTES = 12
focal_class.modifier: private static final
focal_class.original_string: private static final int IV_SIZE_IN_BYTES = 12;
focal_class.type: int
focal_class.var_name: IV_SIZE_IN_BYTES
focal_class.declarator: TAG_SIZE_IN_BYTES = 16
focal_class.modifier: private static final
focal_class.original_string: private static final int TAG_SIZE_IN_BYTES = 16;
focal_class.type: int
focal_class.var_name: TAG_SIZE_IN_BYTES
focal_class.declarator: keySpec
focal_class.modifier: private final
focal_class.original_string: private final SecretKey keySpec;
focal_class.type: SecretKey
focal_class.var_name: keySpec
focal_class.file: java_src/src/main/java/com/google/crypto/tink/aead/subtle/AesGcmSiv.java
focal_class.identifier: AesGcmSiv
focal_class.interfaces: implements Aead
focal_class.class_method_signature: AesGcmSiv.AesGcmSiv(final byte[] key)
focal_class.full_signature: public  AesGcmSiv(final byte[] key)
focal_class.identifier: AesGcmSiv
focal_class.modifiers: public
focal_class.parameters: (final byte[] key)
focal_class.signature:  AesGcmSiv(final byte[] key)
focal_class.class_method_signature: AesGcmSiv.encrypt(final byte[] plaintext, final byte[] associatedData)
focal_class.full_signature: @Override /** * On Android KitKat (API level 19) this method does not support non null or non empty {@code * associatedData}. It might not work at all in older versions. */ public byte[] encrypt(final byte[] plaintext, final byte[] associatedData)
focal_class.identifier: encrypt
focal_class.modifiers: @Override /** * On Android KitKat (API level 19) this method does not support non null or non empty {@code * associatedData}. It might not work at all in older versions. */ public
focal_class.parameters: (final byte[] plaintext, final byte[] associatedData)
focal_class.return: byte[]
focal_class.signature: byte[] encrypt(final byte[] plaintext, final byte[] associatedData)
focal_class.class_method_signature: AesGcmSiv.decrypt(final byte[] ciphertext, final byte[] associatedData)
focal_class.full_signature: @Override /** * On Android KitKat (API level 19) this method does not support non null or non empty {@code * associatedData}. It might not work at all in older versions. */ public byte[] decrypt(final byte[] ciphertext, final byte[] associatedData)
focal_class.identifier: decrypt
focal_class.modifiers: @Override /** * On Android KitKat (API level 19) this method does not support non null or non empty {@code * associatedData}. It might not work at all in older versions. */ public
focal_class.parameters: (final byte[] ciphertext, final byte[] associatedData)
focal_class.return: byte[]
focal_class.signature: byte[] decrypt(final byte[] ciphertext, final byte[] associatedData)
focal_class.class_method_signature: AesGcmSiv.getParams(final byte[] iv)
focal_class.full_signature: private static AlgorithmParameterSpec getParams(final byte[] iv)
focal_class.identifier: getParams
focal_class.modifiers: private static
focal_class.parameters: (final byte[] iv)
focal_class.return: AlgorithmParameterSpec
focal_class.signature: AlgorithmParameterSpec getParams(final byte[] iv)
focal_class.class_method_signature: AesGcmSiv.getParams(final byte[] buf, int offset, int len)
focal_class.full_signature: private static AlgorithmParameterSpec getParams(final byte[] buf, int offset, int len)
focal_class.identifier: getParams
focal_class.modifiers: private static
focal_class.parameters: (final byte[] buf, int offset, int len)
focal_class.return: AlgorithmParameterSpec
focal_class.signature: AlgorithmParameterSpec getParams(final byte[] buf, int offset, int len)
focal_method.body: @Override
    /**
     * On Android KitKat (API level 19) this method does not support non null or non empty {@code
     * associatedData}. It might not work at all in older versions.
     */
    public byte[] decrypt(final byte[] ciphertext, final byte[] associatedData)
        throws GeneralSecurityException {
      if (ciphertext.length < IV_SIZE_IN_BYTES + TAG_SIZE_IN_BYTES) {
        throw new GeneralSecurityException("ciphertext too short");
      }
  
      AlgorithmParameterSpec params = getParams(ciphertext, 0, IV_SIZE_IN_BYTES);
      localCipher.get().init(Cipher.DECRYPT_MODE, keySpec, params);
      if (associatedData != null && associatedData.length != 0) {
        localCipher.get().updateAAD(associatedData);
      }
      return localCipher
          .get()
          .doFinal(ciphertext, IV_SIZE_IN_BYTES, ciphertext.length - IV_SIZE_IN_BYTES);
    }
focal_method.class_method_signature: AesGcmSiv.decrypt(final byte[] ciphertext, final byte[] associatedData)
focal_method.full_signature: @Override /** * On Android KitKat (API level 19) this method does not support non null or non empty {@code * associatedData}. It might not work at all in older versions. */ public byte[] decrypt(final byte[] ciphertext, final byte[] associatedData)
focal_method.identifier: decrypt
focal_method.invocations: getParams init get updateAAD get doFinal get
focal_method.modifiers: @Override /** * On Android KitKat (API level 19) this method does not support non null or non empty {@code * associatedData}. It might not work at all in older versions. */ public
focal_method.parameters: (final byte[] ciphertext, final byte[] associatedData)
focal_method.return: byte[]
focal_method.signature: byte[] decrypt(final byte[] ciphertext, final byte[] associatedData)