Add some compatibility symbols
Change-Id: Ia07aa88be217a73846b0dc12f360cd1aaafcfaba
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69168
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
diff --git a/build.json b/build.json
index 2e675d8..e682971 100644
--- a/build.json
+++ b/build.json
@@ -301,6 +301,7 @@
"crypto/refcount.c",
"crypto/rsa_extra/rsa_asn1.c",
"crypto/rsa_extra/rsa_crypt.c",
+ "crypto/rsa_extra/rsa_extra.c",
"crypto/rsa_extra/rsa_print.c",
"crypto/sha/sha1.c",
"crypto/sha/sha256.c",
diff --git a/crypto/dsa/internal.h b/crypto/dsa/internal.h
index 9cceeb1..61cf9a6 100644
--- a/crypto/dsa/internal.h
+++ b/crypto/dsa/internal.h
@@ -42,8 +42,6 @@
CRYPTO_EX_DATA ex_data;
};
-#define OPENSSL_DSA_MAX_MODULUS_BITS 10000
-
// dsa_check_key performs cheap self-checks on |dsa|, and ensures it is within
// DoS bounds. It returns one on success and zero on error.
int dsa_check_key(const DSA *dsa);
diff --git a/crypto/ec_extra/ec_asn1.c b/crypto/ec_extra/ec_asn1.c
index fb12e48..f17cc50 100644
--- a/crypto/ec_extra/ec_asn1.c
+++ b/crypto/ec_extra/ec_asn1.c
@@ -478,6 +478,41 @@
return CBB_finish_i2d(&cbb, outp);
}
+EC_GROUP *d2i_ECPKParameters(EC_GROUP **out, const uint8_t **inp, long len) {
+ if (len < 0) {
+ return NULL;
+ }
+
+ CBS cbs;
+ CBS_init(&cbs, *inp, (size_t)len);
+ EC_GROUP *ret = EC_KEY_parse_parameters(&cbs);
+ if (ret == NULL) {
+ return NULL;
+ }
+
+ if (out != NULL) {
+ EC_GROUP_free(*out);
+ *out = ret;
+ }
+ *inp = CBS_data(&cbs);
+ return ret;
+}
+
+int i2d_ECPKParameters(const EC_GROUP *group, uint8_t **outp) {
+ if (group == NULL) {
+ OPENSSL_PUT_ERROR(EC, ERR_R_PASSED_NULL_PARAMETER);
+ return -1;
+ }
+
+ CBB cbb;
+ if (!CBB_init(&cbb, 0) || //
+ !EC_KEY_marshal_curve_name(&cbb, group)) {
+ CBB_cleanup(&cbb);
+ return -1;
+ }
+ return CBB_finish_i2d(&cbb, outp);
+}
+
EC_KEY *d2i_ECParameters(EC_KEY **out_key, const uint8_t **inp, long len) {
if (len < 0) {
return NULL;
diff --git a/crypto/fipsmodule/dh/internal.h b/crypto/fipsmodule/dh/internal.h
index d11e59b..9c5830b 100644
--- a/crypto/fipsmodule/dh/internal.h
+++ b/crypto/fipsmodule/dh/internal.h
@@ -26,8 +26,6 @@
#endif
-#define OPENSSL_DH_MAX_MODULUS_BITS 10000
-
struct dh_st {
BIGNUM *p;
BIGNUM *g;
diff --git a/crypto/fipsmodule/rsa/rsa_impl.c.inc b/crypto/fipsmodule/rsa/rsa_impl.c.inc
index 2f1d76b..c7af4fc 100644
--- a/crypto/fipsmodule/rsa/rsa_impl.c.inc
+++ b/crypto/fipsmodule/rsa/rsa_impl.c.inc
@@ -79,10 +79,8 @@
return 0;
}
- // TODO(davidben): 16384-bit RSA is huge. Can we bring this down to a limit of
- // 8192-bit?
unsigned n_bits = BN_num_bits(rsa->n);
- if (n_bits > 16 * 1024) {
+ if (n_bits > OPENSSL_RSA_MAX_MODULUS_BITS) {
OPENSSL_PUT_ERROR(RSA, RSA_R_MODULUS_TOO_LARGE);
return 0;
}
diff --git a/crypto/rsa_extra/rsa_extra.c b/crypto/rsa_extra/rsa_extra.c
new file mode 100644
index 0000000..2ed2c10
--- /dev/null
+++ b/crypto/rsa_extra/rsa_extra.c
@@ -0,0 +1,17 @@
+/* Copyright (c) 2024, Google Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+
+#include <openssl/rsa.h>
+
+void RSA_blinding_off(RSA *rsa) {}
diff --git a/gen/sources.bzl b/gen/sources.bzl
index dce527b..1eef089 100644
--- a/gen/sources.bzl
+++ b/gen/sources.bzl
@@ -396,6 +396,7 @@
"crypto/refcount.c",
"crypto/rsa_extra/rsa_asn1.c",
"crypto/rsa_extra/rsa_crypt.c",
+ "crypto/rsa_extra/rsa_extra.c",
"crypto/rsa_extra/rsa_print.c",
"crypto/sha/sha1.c",
"crypto/sha/sha256.c",
diff --git a/gen/sources.cmake b/gen/sources.cmake
index cf8d5f9..9335959 100644
--- a/gen/sources.cmake
+++ b/gen/sources.cmake
@@ -410,6 +410,7 @@
crypto/refcount.c
crypto/rsa_extra/rsa_asn1.c
crypto/rsa_extra/rsa_crypt.c
+ crypto/rsa_extra/rsa_extra.c
crypto/rsa_extra/rsa_print.c
crypto/sha/sha1.c
crypto/sha/sha256.c
diff --git a/gen/sources.gni b/gen/sources.gni
index 41b4cc1..36b50c8 100644
--- a/gen/sources.gni
+++ b/gen/sources.gni
@@ -396,6 +396,7 @@
"crypto/refcount.c",
"crypto/rsa_extra/rsa_asn1.c",
"crypto/rsa_extra/rsa_crypt.c",
+ "crypto/rsa_extra/rsa_extra.c",
"crypto/rsa_extra/rsa_print.c",
"crypto/sha/sha1.c",
"crypto/sha/sha256.c",
diff --git a/gen/sources.json b/gen/sources.json
index ec5a7e7..9587ab2 100644
--- a/gen/sources.json
+++ b/gen/sources.json
@@ -380,6 +380,7 @@
"crypto/refcount.c",
"crypto/rsa_extra/rsa_asn1.c",
"crypto/rsa_extra/rsa_crypt.c",
+ "crypto/rsa_extra/rsa_extra.c",
"crypto/rsa_extra/rsa_print.c",
"crypto/sha/sha1.c",
"crypto/sha/sha256.c",
diff --git a/include/openssl/dh.h b/include/openssl/dh.h
index 6373bbb..6e6ddb8 100644
--- a/include/openssl/dh.h
+++ b/include/openssl/dh.h
@@ -96,6 +96,10 @@
// Properties.
+// OPENSSL_DH_MAX_MODULUS_BITS is the maximum supported Diffie-Hellman group
+// modulus, in bits.
+#define OPENSSL_DH_MAX_MODULUS_BITS 10000
+
// DH_bits returns the size of |dh|'s group modulus, in bits.
OPENSSL_EXPORT unsigned DH_bits(const DH *dh);
diff --git a/include/openssl/dsa.h b/include/openssl/dsa.h
index f46a8fc..6ebe4aa 100644
--- a/include/openssl/dsa.h
+++ b/include/openssl/dsa.h
@@ -99,6 +99,10 @@
// Properties.
+// OPENSSL_DSA_MAX_MODULUS_BITS is the maximum supported DSA group modulus, in
+// bits.
+#define OPENSSL_DSA_MAX_MODULUS_BITS 10000
+
// DSA_bits returns the size of |dsa|'s group modulus, in bits.
OPENSSL_EXPORT unsigned DSA_bits(const DSA *dsa);
diff --git a/include/openssl/ec_key.h b/include/openssl/ec_key.h
index b7bc74c..e7c7ef9 100644
--- a/include/openssl/ec_key.h
+++ b/include/openssl/ec_key.h
@@ -351,8 +351,24 @@
// Use |EC_KEY_marshal_private_key| instead.
OPENSSL_EXPORT int i2d_ECPrivateKey(const EC_KEY *key, uint8_t **outp);
+// d2i_ECPKParameters parses a DER-encoded ECParameters structure (RFC 5480)
+// from |len| bytes at |*inp|, as described in |d2i_SAMPLE|. For legacy reasons,
+// it recognizes the specifiedCurve form, but only for curves that are already
+// supported as named curves.
+//
+// Use |EC_KEY_parse_parameters| or |EC_KEY_parse_curve_name| instead.
+OPENSSL_EXPORT EC_GROUP *d2i_ECPKParameters(EC_GROUP **out, const uint8_t **inp,
+ long len);
+
+// i2d_ECPKParameters marshals |group| as a DER-encoded ECParameters structure
+// (RFC 5480), as described in |i2d_SAMPLE|.
+//
+// Use |EC_KEY_marshal_curve_name| instead.
+OPENSSL_EXPORT int i2d_ECPKParameters(const EC_GROUP *group, uint8_t **outp);
+
// d2i_ECParameters parses a DER-encoded ECParameters structure (RFC 5480) from
-// |len| bytes at |*inp|, as described in |d2i_SAMPLE|.
+// |len| bytes at |*inp|, as described in |d2i_SAMPLE|. It returns the result as
+// an |EC_KEY| with parameters, but no key, configured.
//
// Use |EC_KEY_parse_parameters| or |EC_KEY_parse_curve_name| instead.
OPENSSL_EXPORT EC_KEY *d2i_ECParameters(EC_KEY **out_key, const uint8_t **inp,
diff --git a/include/openssl/rsa.h b/include/openssl/rsa.h
index 5bf2b50..545b73b 100644
--- a/include/openssl/rsa.h
+++ b/include/openssl/rsa.h
@@ -111,6 +111,11 @@
// Properties.
+// OPENSSL_RSA_MAX_MODULUS_BITS is the maximum supported RSA modulus, in bits.
+//
+// TODO(davidben): Reduce this to 8192.
+#define OPENSSL_RSA_MAX_MODULUS_BITS 16384
+
// RSA_bits returns the size of |rsa|, in bits.
OPENSSL_EXPORT unsigned RSA_bits(const RSA *rsa);
@@ -670,11 +675,8 @@
#define RSA_FLAG_OPAQUE 1
// RSA_FLAG_NO_BLINDING disables blinding of private operations, which is a
-// dangerous thing to do. It is deprecated and should not be used. It will
-// be ignored whenever possible.
-//
-// This flag must be used if a key without the public exponent |e| is used for
-// private key operations; avoid using such keys whenever possible.
+// dangerous thing to do. This flag is set internally as part of self-tests but
+// is otherwise impossible to set externally.
#define RSA_FLAG_NO_BLINDING 8
// RSA_FLAG_EXT_PKEY is deprecated and ignored.
@@ -712,6 +714,9 @@
// RSA_blinding_on returns one.
OPENSSL_EXPORT int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
+// RSA_blinding_off does nothing.
+OPENSSL_EXPORT void RSA_blinding_off(RSA *rsa);
+
// RSA_generate_key behaves like |RSA_generate_key_ex|, which is what you
// should use instead. It returns NULL on error, or a newly-allocated |RSA| on
// success. This function is provided for compatibility only. The |callback|