Make X509_PUBKEY_get0_param take a const pointer

This matches OpenSSL. It is not great because it outputs non-const
pointers, but we have no hope of changing that, and this currently
prevents X509_get_X509_PUBKEY from returning const.

Bug: 442860745
Change-Id: Id14ff6b025a2b454102c468d1b897860862701cb
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/106309
Presubmit-BoringSSL-Verified: boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com <boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Xiangfei Ding <xfding@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/x509/x_pubkey.cc b/crypto/x509/x_pubkey.cc
index 7cce8af..1c39c94 100644
--- a/crypto/x509/x_pubkey.cc
+++ b/crypto/x509/x_pubkey.cc
@@ -183,7 +183,7 @@
 
 int X509_PUBKEY_get0_param(ASN1_OBJECT **out_obj, const uint8_t **out_key,
                            int *out_key_len, X509_ALGOR **out_alg,
-                           X509_PUBKEY *pub) {
+                           const X509_PUBKEY *pub) {
   auto *pub_impl = FromOpaque(pub);
   if (out_obj != nullptr) {
     *out_obj = pub_impl->algor->algorithm;
@@ -193,7 +193,7 @@
     *out_key_len = pub_impl->public_key->length;
   }
   if (out_alg != nullptr) {
-    *out_alg = pub_impl->algor.get();
+    *out_alg = const_cast<X509_ALGOR*>(pub_impl->algor.get());
   }
   return 1;
 }
diff --git a/include/openssl/x509.h b/include/openssl/x509.h
index 8bfc47a..95cbbaf 100644
--- a/include/openssl/x509.h
+++ b/include/openssl/x509.h
@@ -1647,8 +1647,8 @@
 // If `out_alg` is not NULL, it sets `*out_alg` to the AlgorithmIdentifier.
 //
 // All pointers outputted by this function are internal to `pub` and must not be
-// freed by the caller. Additionally, although some outputs are non-const,
-// callers must not mutate the resulting objects.
+// freed by the caller. Additionally, although some outputs are non-const for
+// historical reasons, callers must not mutate the resulting objects.
 //
 // Note: X.509 SubjectPublicKeyInfo structures store the encoded public key as a
 // BIT STRING. `*out_key` and `*out_key_len` will silently pad the key with zero
@@ -1658,7 +1658,7 @@
                                           const uint8_t **out_key,
                                           int *out_key_len,
                                           X509_ALGOR **out_alg,
-                                          X509_PUBKEY *pub);
+                                          const X509_PUBKEY *pub);
 
 // X509_PUBKEY_get0_public_key returns `pub`'s encoded public key.
 OPENSSL_EXPORT const ASN1_BIT_STRING *X509_PUBKEY_get0_public_key(