Skip to content

Commit

Permalink
Adjust tests for OpenSSL 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
beldmit committed Oct 11, 2023
1 parent 4fb4990 commit 3389421
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions regress/unittests/sshkey/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,22 @@ rsa_n(struct sshkey *k)
BIGNUM *n = NULL;
#if (OPENSSL_VERSION_NUMBER < 0x30000000L)
RSA *rsa = NULL;
BIGNUM *res = NULL;
#endif

ASSERT_PTR_NE(k, NULL);
ASSERT_PTR_NE(k->pkey, NULL);
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
EVP_PKEY_get_bn_param(k->pkey, OSSL_PKEY_PARAM_RSA_N, &n);
return n;
#else
rsa = EVP_PKEY_get1_RSA(k->pkey);
ASSERT_PTR_NE(rsa, NULL);
RSA_get0_key(rsa, &n, NULL, NULL);
RSA_free(rsa);
res = BN_dup(n);
return res;
#endif
return n;
}

BIGNUM *
Expand All @@ -113,19 +116,22 @@ rsa_e(struct sshkey *k)
BIGNUM *e = NULL;
#if (OPENSSL_VERSION_NUMBER < 0x30000000L)
RSA *rsa = NULL;
BIGNUM *res = NULL;
#endif

ASSERT_PTR_NE(k, NULL);
ASSERT_PTR_NE(k->pkey, NULL);
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
EVP_PKEY_get_bn_param(k->pkey, OSSL_PKEY_PARAM_RSA_E, &e);
return e;
#else
rsa = EVP_PKEY_get1_RSA(k->pkey);
ASSERT_PTR_NE(rsa, NULL);
RSA_get0_key(rsa, NULL, &e, NULL);
RSA_free(rsa);
res = BN_dup(e);
return res;
#endif
return e;
}

BIGNUM *
Expand All @@ -134,19 +140,22 @@ rsa_p(struct sshkey *k)
BIGNUM *p = NULL;
#if (OPENSSL_VERSION_NUMBER < 0x30000000L)
RSA *rsa = NULL;
BIGNUM *res = NULL;
#endif

ASSERT_PTR_NE(k, NULL);
ASSERT_PTR_NE(k->pkey, NULL);
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
EVP_PKEY_get_bn_param(k->pkey, OSSL_PKEY_PARAM_RSA_FACTOR1, &p);
return p;
#else
rsa = EVP_PKEY_get1_RSA(k->pkey);
ASSERT_PTR_NE(rsa, NULL);
RSA_get0_factors(rsa, &p, NULL);
RSA_free(rsa);
res = BN_dup(p);
return res;
#endif
return p;
}

BIGNUM *
Expand All @@ -155,19 +164,22 @@ rsa_q(struct sshkey *k)
BIGNUM *q = NULL;
#if (OPENSSL_VERSION_NUMBER < 0x30000000L)
RSA *rsa = NULL;
BIGNUM *res = NULL;
#endif

ASSERT_PTR_NE(k, NULL);
ASSERT_PTR_NE(k->pkey, NULL);
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
EVP_PKEY_get_bn_param(k->pkey, OSSL_PKEY_PARAM_RSA_FACTOR2, &q);
return q;
#else
rsa = EVP_PKEY_get1_RSA(k->pkey);
ASSERT_PTR_NE(rsa, NULL);
RSA_get0_factors(rsa, NULL, &q);
RSA_free(rsa);
res = BN_dup(q);
return res;
#endif
return q;
}

const BIGNUM *
Expand Down

0 comments on commit 3389421

Please sign in to comment.