Some more OpenSSL 1.1.0 compat APIs
[folly.git] / folly / portability / OpenSSL.cpp
index 53b020c73d0069dcbf4816c30d49a932c81e3f8f..7fdb7b7264d3cd8a7e2db6a75e3c07a81bd6c3e9 100644 (file)
@@ -62,6 +62,40 @@ int SSL_SESSION_up_ref(SSL_SESSION* session) {
 int X509_up_ref(X509* x) {
   return CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
 }
+
+int EVP_PKEY_up_ref(EVP_PKEY* evp) {
+  return CRYPTO_add(&evp->references, 1, CRYPTO_LOCK_EVP_PKEY);
+}
+
+void RSA_get0_key(
+    const RSA* r,
+    const BIGNUM** n,
+    const BIGNUM** e,
+    const BIGNUM** d) {
+  if (n != nullptr) {
+    *n = r->n;
+  }
+  if (e != nullptr) {
+    *e = r->e;
+  }
+  if (d != nullptr) {
+    *d = r->d;
+  }
+}
+
+RSA* EVP_PKEY_get0_RSA(EVP_PKEY* pkey) {
+  if (pkey->type != EVP_PKEY_RSA) {
+    return nullptr;
+  }
+  return pkey->pkey.rsa;
+}
+
+EC_KEY* EVP_PKEY_get0_EC_KEY(EVP_PKEY* pkey) {
+  if (pkey->type != EVP_PKEY_EC) {
+    return nullptr;
+  }
+  return pkey->pkey.ec;
+}
 #endif
 
 #if !FOLLY_OPENSSL_IS_110
@@ -97,8 +131,8 @@ unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION* s) {
 
 // This is taken from OpenSSL 1.1.0
 int DH_set0_pqg(DH* dh, BIGNUM* p, BIGNUM* q, BIGNUM* g) {
-  /* If the fields p and g in d are NULL, the corresponding input
-   * parameters MUST be non-NULL.  q may remain NULL.
+  /* If the fields p and g in d are nullptr, the corresponding input
+   * parameters MUST not be nullptr.  q may remain nullptr.
    */
   if (dh == nullptr || (dh->p == nullptr && p == nullptr) ||
       (dh->g == nullptr && g == nullptr)) {
@@ -174,7 +208,6 @@ void HMAC_CTX_free(HMAC_CTX* ctx) {
 }
 
 #endif
-
 }
 }
 }