Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP avoid deprecated stuff in openssl 3 #332

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bolos/cx_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ int sys_cx_math_is_prime(const uint8_t *r, unsigned int len)
rr = BN_new();
BN_bin2bn(r, len, rr);

#if OPENSSL_VERSION_MAJOR >= 3
ret = BN_check_prime(rr, ctx, NULL);
#else
ret = BN_is_prime_ex(rr, 64, ctx, NULL);
#endif

BN_free(rr);
BN_CTX_free(ctx);
Expand Down
13 changes: 11 additions & 2 deletions src/bolos/cx_mpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,15 @@ cx_err_t cx_mpi_mod_pow(cx_mpi_t *r, const cx_mpi_t *a, const cx_mpi_t *e,
return error;
}

static inline int cx_mpi_openssl_is_prime(const cx_mpi_t *p)
{
#if OPENSSL_VERSION_MAJOR >= 3
return BN_check_prime(p, local_bn_ctx, NULL);
#else
return BN_is_prime_ex(p, 64, local_bn_ctx, NULL);
#endif
}

cx_err_t cx_mpi_is_prime(cx_mpi_t *x, bool *prime)
{
cx_err_t error;
Expand All @@ -1130,7 +1139,7 @@ cx_err_t cx_mpi_is_prime(cx_mpi_t *x, bool *prime)
*prime = false;
error = CX_OK;

if ((is_prime = BN_is_prime_ex(x, 64, local_bn_ctx, NULL)) == 1) {
if ((is_prime = cx_mpi_openssl_is_prime(x)) == 1) {
*prime = true;
} else if (is_prime < 0) {
error = CX_INTERNAL_ERROR;
Expand All @@ -1154,7 +1163,7 @@ cx_err_t cx_mpi_next_prime(cx_mpi_t *x)
error = CX_OK;
do {
if (!BN_add_word(x, 2) || (cx_mpi_nbytes(x) > x_size) ||
((is_prime = BN_is_prime_ex(x, 64, local_bn_ctx, NULL)) < 0)) {
((is_prime = cx_mpi_openssl_is_prime(x)) < 0)) {

if (cx_mpi_nbytes(x) > x_size)
error = CX_OVERFLOW;
Expand Down
4 changes: 4 additions & 0 deletions src/bolos/cx_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ int sys_cx_math_next_prime(uint8_t *buf, unsigned int len)
errx(1, "BN_add_word");
}

#if OPENSSL_VERSION_MAJOR >= 3
ret = BN_check_prime(p, ctx, NULL);
#else
ret = BN_is_prime_ex(p, 20, ctx, NULL);
#endif
} while (ret == 0);

if (ret == -1) {
Expand Down