Add EVP_PKEY_eq and EVP_PKEY_parameters_eq

The new names are better so, matching OpenSSL, deprecate the cmp
spelling. We have a lot of callers in the library so a follow-up CL will
switch existing calls.

Bug: 497675628
Change-Id: I956c70e5c96b0b056becdff0b0ad89f8b2c4bf77
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/91909
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/evp/evp.cc b/crypto/evp/evp.cc
index 0836a07..fafe0cc 100644
--- a/crypto/evp/evp.cc
+++ b/crypto/evp/evp.cc
@@ -67,9 +67,9 @@
   return 0;
 }
 
-int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b) {
+int EVP_PKEY_eq(const EVP_PKEY *a, const EVP_PKEY *b) {
   // This also checks that |EVP_PKEY_id| matches.
-  if (!EVP_PKEY_cmp_parameters(a, b)) {
+  if (!EVP_PKEY_parameters_eq(a, b)) {
     return 0;
   }
 
@@ -80,6 +80,10 @@
          a_impl->ameth->pub_equal(a_impl, b_impl);
 }
 
+int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b) {
+  return EVP_PKEY_eq(a, b);
+}
+
 int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) {
   auto *to_impl = FromOpaque(to);
   auto *from_impl = FromOpaque(from);
@@ -324,7 +328,7 @@
   return impl->ameth->get_pub_raw(impl, out, out_len);
 }
 
-int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) {
+int EVP_PKEY_parameters_eq(const EVP_PKEY *a, const EVP_PKEY *b) {
   if (EVP_PKEY_id(a) != EVP_PKEY_id(b)) {
     return 0;
   }
@@ -339,6 +343,10 @@
   return 1;
 }
 
+int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) {
+  return EVP_PKEY_parameters_eq(a, b);
+}
+
 int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) {
   return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_MD, 0,
                            (void *)md);
diff --git a/include/openssl/evp.h b/include/openssl/evp.h
index cfeca08..b1600c7 100644
--- a/include/openssl/evp.h
+++ b/include/openssl/evp.h
@@ -61,11 +61,9 @@
 // an error to attempt to duplicate, export, or compare an opaque key.
 OPENSSL_EXPORT int EVP_PKEY_is_opaque(const EVP_PKEY *pkey);
 
-// EVP_PKEY_cmp compares |a| and |b| and returns one if their public keys are
+// EVP_PKEY_eq compares |a| and |b| and returns one if their public keys are
 // equal and zero otherwise.
-//
-// WARNING: this differs from the traditional return value of a "cmp" function.
-OPENSSL_EXPORT int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b);
+OPENSSL_EXPORT int EVP_PKEY_eq(const EVP_PKEY *a, const EVP_PKEY *b);
 
 // EVP_PKEY_copy_parameters sets the parameters of |to| to equal the parameters
 // of |from|. It returns one on success and zero on error.
@@ -75,13 +73,10 @@
 // parameters or zero if not, or if the algorithm doesn't take parameters.
 OPENSSL_EXPORT int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey);
 
-// EVP_PKEY_cmp_parameters compares the parameters of |a| and |b|. It returns
-// one if they match and zero otherwise. In algorithms that do not use
-// parameters, this function returns one; null parameters are vacuously equal.
-//
-// WARNING: this differs from the traditional return value of a "cmp" function.
-OPENSSL_EXPORT int EVP_PKEY_cmp_parameters(const EVP_PKEY *a,
-                                           const EVP_PKEY *b);
+// EVP_PKEY_parameters_eq compares the parameters of |a| and |b|. It returns one
+// if they match and zero otherwise. In algorithms that do not use parameters,
+// this function returns one; null parameters are vacuously equal.
+OPENSSL_EXPORT int EVP_PKEY_parameters_eq(const EVP_PKEY *a, const EVP_PKEY *b);
 
 // EVP_PKEY_size returns the maximum size, in bytes, of a signature signed by
 // |pkey|. For an RSA key, this returns the number of bytes needed to represent
@@ -1454,6 +1449,19 @@
                                                      const uint8_t *in,
                                                      size_t len);
 
+// EVP_PKEY_cmp calls |EVP_PKEY_eq|. It returns one if public keys are equal and
+// zero otherwise.
+//
+// WARNING: This differs from the traditional return value of a "cmp" function.
+OPENSSL_EXPORT int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b);
+
+// EVP_PKEY_cmp_parameters calls |EVP_PKEY_parameters_eq|. It returns one if
+// parameters are equal and zero otherwise.
+//
+// WARNING: This differs from the traditional return value of a "cmp" function.
+OPENSSL_EXPORT int EVP_PKEY_cmp_parameters(const EVP_PKEY *a,
+                                           const EVP_PKEY *b);
+
 
 // Preprocessor compatibility section (hidden).
 //
diff --git a/include/openssl/prefix_symbols.h b/include/openssl/prefix_symbols.h
index 5aa094a..2b51e60 100644
--- a/include/openssl/prefix_symbols.h
+++ b/include/openssl/prefix_symbols.h
@@ -1148,6 +1148,7 @@
 #pragma redefine_extname EVP_PKEY_encapsulate_init BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_encapsulate_init)
 #pragma redefine_extname EVP_PKEY_encrypt BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_encrypt)
 #pragma redefine_extname EVP_PKEY_encrypt_init BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_encrypt_init)
+#pragma redefine_extname EVP_PKEY_eq BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_eq)
 #pragma redefine_extname EVP_PKEY_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_free)
 #pragma redefine_extname EVP_PKEY_from_private_key_info BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_from_private_key_info)
 #pragma redefine_extname EVP_PKEY_from_private_seed BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_from_private_seed)
@@ -1180,6 +1181,7 @@
 #pragma redefine_extname EVP_PKEY_new BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_new)
 #pragma redefine_extname EVP_PKEY_new_raw_private_key BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_new_raw_private_key)
 #pragma redefine_extname EVP_PKEY_new_raw_public_key BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_new_raw_public_key)
+#pragma redefine_extname EVP_PKEY_parameters_eq BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_parameters_eq)
 #pragma redefine_extname EVP_PKEY_paramgen BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_paramgen)
 #pragma redefine_extname EVP_PKEY_paramgen_init BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_paramgen_init)
 #pragma redefine_extname EVP_PKEY_print_params BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_PKEY_print_params)
@@ -4233,6 +4235,7 @@
 #define EVP_PKEY_encapsulate_init BORINGSSL_ADD_PREFIX(EVP_PKEY_encapsulate_init)
 #define EVP_PKEY_encrypt BORINGSSL_ADD_PREFIX(EVP_PKEY_encrypt)
 #define EVP_PKEY_encrypt_init BORINGSSL_ADD_PREFIX(EVP_PKEY_encrypt_init)
+#define EVP_PKEY_eq BORINGSSL_ADD_PREFIX(EVP_PKEY_eq)
 #define EVP_PKEY_free BORINGSSL_ADD_PREFIX(EVP_PKEY_free)
 #define EVP_PKEY_from_private_key_info BORINGSSL_ADD_PREFIX(EVP_PKEY_from_private_key_info)
 #define EVP_PKEY_from_private_seed BORINGSSL_ADD_PREFIX(EVP_PKEY_from_private_seed)
@@ -4265,6 +4268,7 @@
 #define EVP_PKEY_new BORINGSSL_ADD_PREFIX(EVP_PKEY_new)
 #define EVP_PKEY_new_raw_private_key BORINGSSL_ADD_PREFIX(EVP_PKEY_new_raw_private_key)
 #define EVP_PKEY_new_raw_public_key BORINGSSL_ADD_PREFIX(EVP_PKEY_new_raw_public_key)
+#define EVP_PKEY_parameters_eq BORINGSSL_ADD_PREFIX(EVP_PKEY_parameters_eq)
 #define EVP_PKEY_paramgen BORINGSSL_ADD_PREFIX(EVP_PKEY_paramgen)
 #define EVP_PKEY_paramgen_init BORINGSSL_ADD_PREFIX(EVP_PKEY_paramgen_init)
 #define EVP_PKEY_print_params BORINGSSL_ADD_PREFIX(EVP_PKEY_print_params)