test_class.file: java_src/src/test/java/com/google/crypto/tink/subtle/X25519Test.java
test_class.identifier: X25519Test
test_case.body: @Test
    public void testComputeSharedSecretWithWycheproofVectors() throws Exception {
      JSONObject json =
          WycheproofTestUtil.readJson("../wycheproof/testvectors/x25519_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);
        JSONArray tests = group.getJSONArray("tests");
        String curve = group.getString("curve");
        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"));
          String result = testcase.getString("result");
          String hexPubKey = testcase.getString("public");
          String hexPrivKey = testcase.getString("private");
          String expectedSharedSecret = testcase.getString("shared");
          if (!curve.equals("curve25519")) {
            System.out.printf("Skipping %s, unknown curve name: %s", tcId, curve);
            cntSkippedTests++;
            continue;
          }
          try {
            String sharedSecret =
                Hex.encode(X25519.computeSharedSecret(Hex.decode(hexPrivKey), Hex.decode(hexPubKey)));
            if (result.equals("invalid")) {
              System.out.printf(
                  "FAIL %s: accepting invalid parameters, shared secret: %s%n", tcId, sharedSecret);
              errors++;
            } else if (!expectedSharedSecret.equals(sharedSecret)) {
              System.out.printf(
                  "FAIL %s: incorrect shared secret, computed: %s, expected: %s%n",
                  tcId, sharedSecret, expectedSharedSecret);
              errors++;
            }
          } catch (GeneralSecurityException ex) {
            if (result.equals("valid")) {
              System.out.printf("FAIL %s, exception %s%n", tcId, ex);
              errors++;
            }
          } catch (Exception ex) {
            // Other exceptions typically indicate that something is wrong with the implementation.
            System.out.printf("FAIL %s, exception %s%n", tcId, ex);
            errors++;
          }
        }
      }
      System.out.printf("Number of tests skipped: %d", cntSkippedTests);
      assertEquals(0, errors);
    }
test_case.class_method_signature: X25519Test.testComputeSharedSecretWithWycheproofVectors()
test_case.full_signature: @Test public void testComputeSharedSecretWithWycheproofVectors()
test_case.identifier: testComputeSharedSecretWithWycheproofVectors
test_case.invocations: readJson getJSONArray length getJSONObject getJSONArray getString length getJSONObject format getInt getString getString getString getString getString equals printf encode computeSharedSecret decode decode equals printf equals printf equals printf printf printf assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testComputeSharedSecretWithWycheproofVectors()
focal_class.file: java_src/src/main/java/com/google/crypto/tink/subtle/X25519.java
focal_class.identifier: X25519
focal_class.class_method_signature: X25519.generatePrivateKey()
focal_class.full_signature: @SuppressWarnings("NarrowingCompoundAssignment") public static byte[] generatePrivateKey()
focal_class.identifier: generatePrivateKey
focal_class.modifiers: @SuppressWarnings("NarrowingCompoundAssignment") public static
focal_class.parameters: ()
focal_class.return: byte[]
focal_class.signature: byte[] generatePrivateKey()
focal_class.class_method_signature: X25519.computeSharedSecret(byte[] privateKey, byte[] peersPublicValue)
focal_class.full_signature: @SuppressWarnings("NarrowingCompoundAssignment") public static byte[] computeSharedSecret(byte[] privateKey, byte[] peersPublicValue)
focal_class.identifier: computeSharedSecret
focal_class.modifiers: @SuppressWarnings("NarrowingCompoundAssignment") public static
focal_class.parameters: (byte[] privateKey, byte[] peersPublicValue)
focal_class.return: byte[]
focal_class.signature: byte[] computeSharedSecret(byte[] privateKey, byte[] peersPublicValue)
focal_class.class_method_signature: X25519.publicFromPrivate(byte[] privateKey)
focal_class.full_signature: public static byte[] publicFromPrivate(byte[] privateKey)
focal_class.identifier: publicFromPrivate
focal_class.modifiers: public static
focal_class.parameters: (byte[] privateKey)
focal_class.return: byte[]
focal_class.signature: byte[] publicFromPrivate(byte[] privateKey)
focal_method.body: @SuppressWarnings("NarrowingCompoundAssignment")
    public static byte[] computeSharedSecret(byte[] privateKey, byte[] peersPublicValue)
        throws InvalidKeyException {
      if (privateKey.length != Field25519.FIELD_LEN) {
        throw new InvalidKeyException("Private key must have 32 bytes.");
      }
      long[] x = new long[Field25519.LIMB_CNT + 1];
  
      byte[] e = Arrays.copyOf(privateKey, Field25519.FIELD_LEN);
      e[0] &= 248;
      e[31] &= 127;
      e[31] |= 64;
  
      Curve25519.curveMult(x, e, peersPublicValue);
      return Field25519.contract(x);
    }
focal_method.class_method_signature: X25519.computeSharedSecret(byte[] privateKey, byte[] peersPublicValue)
focal_method.full_signature: @SuppressWarnings("NarrowingCompoundAssignment") public static byte[] computeSharedSecret(byte[] privateKey, byte[] peersPublicValue)
focal_method.identifier: computeSharedSecret
focal_method.invocations: copyOf curveMult contract
focal_method.modifiers: @SuppressWarnings("NarrowingCompoundAssignment") public static
focal_method.parameters: (byte[] privateKey, byte[] peersPublicValue)
focal_method.return: byte[]
focal_method.signature: byte[] computeSharedSecret(byte[] privateKey, byte[] peersPublicValue)