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
    /**
     * This is a very simple test for the randomness of the nonce. The test simply checks that the
     * multiple ciphertexts of the same message are distinct.
     */
    public void testRandomNonce() throws Exception {
      final int samples = 1 << 17;
      byte[] key = Random.randBytes(16);
      byte[] message = new byte[0];
      byte[] aad = new byte[0];
      AesGcmSiv gcm = new AesGcmSiv(key);
      HashSet<String> ciphertexts = new HashSet<String>();
      for (int i = 0; i < samples; i++) {
        byte[] ct = gcm.encrypt(message, aad);
        String ctHex = TestUtil.hexEncode(ct);
        assertFalse(ciphertexts.contains(ctHex));
        ciphertexts.add(ctHex);
      }
    }
test_case.class_method_signature: AesGcmSivTest.testRandomNonce()
test_case.full_signature: @Test /** * This is a very simple test for the randomness of the nonce. The test simply checks that the * multiple ciphertexts of the same message are distinct. */ public void testRandomNonce()
test_case.identifier: testRandomNonce
test_case.invocations: randBytes encrypt hexEncode assertFalse contains add
test_case.modifiers: @Test /** * This is a very simple test for the randomness of the nonce. The test simply checks that the * multiple ciphertexts of the same message are distinct. */ public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testRandomNonce()
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[] encrypt(final byte[] plaintext, final byte[] associatedData)
        throws GeneralSecurityException {
      // Check that ciphertext is not longer than the max. size of a Java array.
      if (plaintext.length > Integer.MAX_VALUE - IV_SIZE_IN_BYTES - TAG_SIZE_IN_BYTES) {
        throw new GeneralSecurityException("plaintext too long");
      }
      byte[] ciphertext = new byte[IV_SIZE_IN_BYTES + plaintext.length + TAG_SIZE_IN_BYTES];
      byte[] iv = Random.randBytes(IV_SIZE_IN_BYTES);
      System.arraycopy(iv, 0, ciphertext, 0, IV_SIZE_IN_BYTES);
  
      AlgorithmParameterSpec params = getParams(iv);
      localCipher.get().init(Cipher.ENCRYPT_MODE, keySpec, params);
      if (associatedData != null && associatedData.length != 0) {
        localCipher.get().updateAAD(associatedData);
      }
      int written =
          localCipher.get().doFinal(plaintext, 0, plaintext.length, ciphertext, IV_SIZE_IN_BYTES);
      // For security reasons, AES-GCM encryption must always use tag of TAG_SIZE_IN_BYTES bytes. If
      // so, written must be equal to plaintext.length + TAG_SIZE_IN_BYTES.
  
      if (written != plaintext.length + TAG_SIZE_IN_BYTES) {
        // The tag is shorter than expected.
        int actualTagSize = written - plaintext.length;
        throw new GeneralSecurityException(
            String.format(
                "encryption failed; GCM tag must be %s bytes, but got only %s bytes",
                TAG_SIZE_IN_BYTES, actualTagSize));
      }
      return ciphertext;
    }
focal_method.class_method_signature: AesGcmSiv.encrypt(final byte[] plaintext, 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[] encrypt(final byte[] plaintext, final byte[] associatedData)
focal_method.identifier: encrypt
focal_method.invocations: randBytes arraycopy getParams init get updateAAD get doFinal get format
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[] plaintext, final byte[] associatedData)
focal_method.return: byte[]
focal_method.signature: byte[] encrypt(final byte[] plaintext, final byte[] associatedData)