Add some more OpenSSL 1.1 APIs for folly/portability/
[folly.git] / folly / portability / OpenSSL.cpp
index bc16af6e5338476215aea63fe3278121081c4598..492b830625ef3563f2f87bd535d7ab8246528f2e 100644 (file)
@@ -90,6 +90,20 @@ RSA* EVP_PKEY_get0_RSA(EVP_PKEY* pkey) {
   return pkey->pkey.rsa;
 }
 
+DSA* EVP_PKEY_get0_DSA(EVP_PKEY* pkey) {
+  if (pkey->type != EVP_PKEY_DSA) {
+    return nullptr;
+  }
+  return pkey->pkey.dsa;
+}
+
+DH* EVP_PKEY_get0_DH(EVP_PKEY* pkey) {
+  if (pkey->type != EVP_PKEY_DH) {
+    return nullptr;
+  }
+  return pkey->pkey.dh;
+}
+
 EC_KEY* EVP_PKEY_get0_EC_KEY(EVP_PKEY* pkey) {
   if (pkey->type != EVP_PKEY_EC) {
     return nullptr;
@@ -163,6 +177,66 @@ int DH_set0_pqg(DH* dh, BIGNUM* p, BIGNUM* q, BIGNUM* g) {
   return 1;
 }
 
+void DH_get0_pqg(
+    const DH* dh,
+    const BIGNUM** p,
+    const BIGNUM** q,
+    const BIGNUM** g) {
+  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
+  if (p != nullptr) {
+    *p = dh->p;
+  }
+  if (q != nullptr) {
+    *q = dh->q;
+  }
+  if (g != nullptr) {
+    *g = dh->g;
+  }
+}
+
+void DH_get0_key(
+    const DH* dh,
+    const BIGNUM** pub_key,
+    const BIGNUM** priv_key) {
+  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
+  if (pub_key != nullptr) {
+    *pub_key = dh->pub_key;
+  }
+  if (priv_key != nullptr) {
+    *priv_key = dh->priv_key;
+  }
+}
+
+void DSA_get0_pqg(
+    const DSA* dsa,
+    const BIGNUM** p,
+    const BIGNUM** q,
+    const BIGNUM** g) {
+  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
+  if (p != nullptr) {
+    *p = dsa->p;
+  }
+  if (q != nullptr) {
+    *q = dsa->q;
+  }
+  if (g != nullptr) {
+    *g = dsa->g;
+  }
+}
+
+void DSA_get0_key(
+    const DSA* dsa,
+    const BIGNUM** pub_key,
+    const BIGNUM** priv_key) {
+  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
+  if (pub_key != nullptr) {
+    *pub_key = dsa->pub_key;
+  }
+  if (priv_key != nullptr) {
+    *priv_key = dsa->priv_key;
+  }
+}
+
 X509* X509_STORE_CTX_get0_cert(X509_STORE_CTX* ctx) {
   return ctx->cert;
 }
@@ -210,9 +284,9 @@ void HMAC_CTX_free(HMAC_CTX* ctx) {
 bool RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d) {
   // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
   /**
-   * 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 the fields n and e in r are nullptr, the corresponding input parameters
+   * MUST be non-nullptr for n and e. d may be left NULL (in case only the
+   * public key is used).
    */
   if ((r->n == nullptr && n == nullptr) || (r->e == nullptr && e == nullptr)) {
     return false;
@@ -232,6 +306,33 @@ bool RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d) {
   return true;
 }
 
+void RSA_get0_factors(const RSA* r, const BIGNUM** p, const BIGNUM** q) {
+  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
+  if (p != nullptr) {
+    *p = r->p;
+  }
+  if (q != nullptr) {
+    *q = r->q;
+  }
+}
+
+void RSA_get0_crt_params(
+    const RSA* r,
+    const BIGNUM** dmp1,
+    const BIGNUM** dmq1,
+    const BIGNUM** iqmp) {
+  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
+  if (dmp1 != nullptr) {
+    *dmp1 = r->dmp1;
+  }
+  if (dmq1 != nullptr) {
+    *dmq1 = r->dmq1;
+  }
+  if (iqmp != nullptr) {
+    *iqmp = r->iqmp;
+  }
+}
+
 #endif
 }
 }