]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use the special shims file for RSA shims
authorAram Sargsyan <aram@isc.org>
Sun, 26 Sep 2021 18:53:38 +0000 (18:53 +0000)
committerAram Sargsyan <aram@isc.org>
Thu, 28 Oct 2021 07:38:56 +0000 (07:38 +0000)
Since we now have a separate `openssl_shim.{c,h}` files in the `dns`
library, we can place the exisintg shims there.

lib/dns/openssl_shim.c
lib/dns/openssl_shim.h
lib/dns/opensslrsa_link.c

index 143ccbcfe8abee2fc6afe8d5b3a53fffa21421da..43264b8383e0d456eac805cc629f3086735287d1 100644 (file)
 
 #include "openssl_shim.h"
 
-#include <openssl/bn.h>
-#include <openssl/ecdsa.h>
-#include <openssl/err.h>
+#if !HAVE_RSA_SET0_KEY && OPENSSL_VERSION_NUMBER < 0x30000000L
+/* From OpenSSL 1.1.0 */
+int
+RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) {
+       /*
+        * If the fields n and e in r are NULL, the corresponding input
+        * parameters MUST be non-NULL for n and e.  d may be
+        * left NULL (in case only the public key is used).
+        */
+       if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL)) {
+               return (0);
+       }
+
+       if (n != NULL) {
+               BN_free(r->n);
+               r->n = n;
+       }
+       if (e != NULL) {
+               BN_free(r->e);
+               r->e = e;
+       }
+       if (d != NULL) {
+               BN_clear_free(r->d);
+               r->d = d;
+       }
+
+       return (1);
+}
+
+int
+RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q) {
+       /*
+        * If the fields p and q in r are NULL, the corresponding input
+        * parameters MUST be non-NULL.
+        */
+       if ((r->p == NULL && p == NULL) || (r->q == NULL && q == NULL)) {
+               return (0);
+       }
+
+       if (p != NULL) {
+               BN_clear_free(r->p);
+               r->p = p;
+       }
+       if (q != NULL) {
+               BN_clear_free(r->q);
+               r->q = q;
+       }
+
+       return (1);
+}
+
+int
+RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) {
+       /*
+        * If the fields dmp1, dmq1 and iqmp in r are NULL, the
+        * corresponding input parameters MUST be non-NULL.
+        */
+       if ((r->dmp1 == NULL && dmp1 == NULL) ||
+           (r->dmq1 == NULL && dmq1 == NULL) ||
+           (r->iqmp == NULL && iqmp == NULL))
+       {
+               return (0);
+       }
+
+       if (dmp1 != NULL) {
+               BN_clear_free(r->dmp1);
+               r->dmp1 = dmp1;
+       }
+       if (dmq1 != NULL) {
+               BN_clear_free(r->dmq1);
+               r->dmq1 = dmq1;
+       }
+       if (iqmp != NULL) {
+               BN_clear_free(r->iqmp);
+               r->iqmp = iqmp;
+       }
+
+       return (1);
+}
+
+void
+RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e,
+            const BIGNUM **d) {
+       if (n != NULL) {
+               *n = r->n;
+       }
+       if (e != NULL) {
+               *e = r->e;
+       }
+       if (d != NULL) {
+               *d = r->d;
+       }
+}
+
+void
+RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q) {
+       if (p != NULL) {
+               *p = r->p;
+       }
+       if (q != NULL) {
+               *q = r->q;
+       }
+}
+
+void
+RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1,
+                   const BIGNUM **iqmp) {
+       if (dmp1 != NULL) {
+               *dmp1 = r->dmp1;
+       }
+       if (dmq1 != NULL) {
+               *dmq1 = r->dmq1;
+       }
+       if (iqmp != NULL) {
+               *iqmp = r->iqmp;
+       }
+}
+
+int
+RSA_test_flags(const RSA *r, int flags) {
+       return (r->flags & flags);
+}
+#endif /* !HAVE_RSA_SET0_KEY && OPENSSL_VERSION_NUMBER < 0x30000000L */
 
 #if !HAVE_ECDSA_SIG_GET0
 /* From OpenSSL 1.1 */
index c2ada37714580a2c72cde1877413acc11c25ebbf..e386cf858aac2a6be39aba78b2f8d367b7d6bc20 100644 (file)
 #include <openssl/bn.h>
 #include <openssl/ecdsa.h>
 #include <openssl/err.h>
+#include <openssl/opensslv.h>
+#include <openssl/rsa.h>
+
+/*
+ * Limit the size of public exponents.
+ */
+#ifndef RSA_MAX_PUBEXP_BITS
+#define RSA_MAX_PUBEXP_BITS 35
+#endif /* ifndef RSA_MAX_PUBEXP_BITS */
+
+#if !HAVE_RSA_SET0_KEY && OPENSSL_VERSION_NUMBER < 0x30000000L
+int
+RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
+
+int
+RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
+
+int
+RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
+
+void
+RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e,
+            const BIGNUM **d);
+
+void
+RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
+
+void
+RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1,
+                   const BIGNUM **iqmp);
+
+int
+RSA_test_flags(const RSA *r, int flags);
+#endif /* !HAVE_RSA_SET0_KEY && OPENSSL_VERSION_NUMBER < 0x30000000L */
 
 #if !HAVE_ECDSA_SIG_GET0
 void
index 91f62081857d1658bfcdd9cedc97bcba7e746ff0..bf828402a2d4fbf6cae6682b49bbdcd3607d8001 100644 (file)
@@ -15,6 +15,9 @@
 #include <stdbool.h>
 
 #include <openssl/bn.h>
+#if !defined(OPENSSL_NO_ENGINE)
+#include <openssl/engine.h>
+#endif /* if !defined(OPENSSL_NO_ENGINE) */
 #include <openssl/err.h>
 #include <openssl/objects.h>
 #include <openssl/rsa.h>
 #include "dst_internal.h"
 #include "dst_openssl.h"
 #include "dst_parse.h"
-#if !defined(OPENSSL_NO_ENGINE)
-#include <openssl/engine.h>
-#endif /* if !defined(OPENSSL_NO_ENGINE) */
-
-/*
- * Limit the size of public exponents.
- */
-#ifndef RSA_MAX_PUBEXP_BITS
-#define RSA_MAX_PUBEXP_BITS 35
-#endif /* ifndef RSA_MAX_PUBEXP_BITS */
+#include "openssl_shim.h"
 
 #define DST_RET(a)        \
        {                 \
                goto err; \
        }
 
-#if !HAVE_RSA_SET0_KEY
-/* From OpenSSL 1.1.0 */
-static int
-RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) {
-       /*
-        * If the fields n and e in r are NULL, the corresponding input
-        * parameters MUST be non-NULL for n and e.  d may be
-        * left NULL (in case only the public key is used).
-        */
-       if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL)) {
-               return (0);
-       }
-
-       if (n != NULL) {
-               BN_free(r->n);
-               r->n = n;
-       }
-       if (e != NULL) {
-               BN_free(r->e);
-               r->e = e;
-       }
-       if (d != NULL) {
-               BN_free(r->d);
-               r->d = d;
-       }
-
-       return (1);
-}
-
-static int
-RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q) {
-       /*
-        * If the fields p and q in r are NULL, the corresponding input
-        * parameters MUST be non-NULL.
-        */
-       if ((r->p == NULL && p == NULL) || (r->q == NULL && q == NULL)) {
-               return (0);
-       }
-
-       if (p != NULL) {
-               BN_free(r->p);
-               r->p = p;
-       }
-       if (q != NULL) {
-               BN_free(r->q);
-               r->q = q;
-       }
-
-       return (1);
-}
-
-static int
-RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) {
-       /*
-        * If the fields dmp1, dmq1 and iqmp in r are NULL, the
-        * corresponding input parameters MUST be non-NULL.
-        */
-       if ((r->dmp1 == NULL && dmp1 == NULL) ||
-           (r->dmq1 == NULL && dmq1 == NULL) ||
-           (r->iqmp == NULL && iqmp == NULL))
-       {
-               return (0);
-       }
-
-       if (dmp1 != NULL) {
-               BN_free(r->dmp1);
-               r->dmp1 = dmp1;
-       }
-       if (dmq1 != NULL) {
-               BN_free(r->dmq1);
-               r->dmq1 = dmq1;
-       }
-       if (iqmp != NULL) {
-               BN_free(r->iqmp);
-               r->iqmp = iqmp;
-       }
-
-       return (1);
-}
-
-static void
-RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e,
-            const BIGNUM **d) {
-       if (n != NULL) {
-               *n = r->n;
-       }
-       if (e != NULL) {
-               *e = r->e;
-       }
-       if (d != NULL) {
-               *d = r->d;
-       }
-}
-
-static void
-RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q) {
-       if (p != NULL) {
-               *p = r->p;
-       }
-       if (q != NULL) {
-               *q = r->q;
-       }
-}
-
-static void
-RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1,
-                   const BIGNUM **iqmp) {
-       if (dmp1 != NULL) {
-               *dmp1 = r->dmp1;
-       }
-       if (dmq1 != NULL) {
-               *dmq1 = r->dmq1;
-       }
-       if (iqmp != NULL) {
-               *iqmp = r->iqmp;
-       }
-}
-
-static int
-RSA_test_flags(const RSA *r, int flags) {
-       return (r->flags & flags);
-}
-
-#endif /* !HAVE_RSA_SET0_KEY */
-
 static isc_result_t
 opensslrsa_createctx(dst_key_t *key, dst_context_t *dctx) {
        EVP_MD_CTX *evp_md_ctx;