Skip to content

Commit afc7e12

Browse files
authored
fix: use BN_GENCB_get_arg accessor for OpenSSL 3.x compatibility (#16)
* fix: use BN_GENCB_get_arg accessor * fix: remove cipher.h include as it's not in 3.x
1 parent acd92db commit afc7e12

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

src/ncrypto.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <openssl/pkcs12.h>
99
#include <openssl/rand.h>
1010
#include <openssl/x509v3.h>
11-
#include "openssl/cipher.h"
1211

1312
#ifndef NCRYPTO_NO_KDF_H
1413
#include <openssl/kdf.h>
@@ -473,11 +472,9 @@ int BignumPointer::isPrime(int nchecks,
473472
// TODO(@jasnell): This could be refactored to allow inlining.
474473
// Not too important right now tho.
475474
[](int a, int b, BN_GENCB* ctx) mutable -> int {
476-
PrimeCheckCallback& ptr = *static_cast<PrimeCheckCallback*>(ctx->arg);
477-
// Newer versions of openssl and boringssl define the BN_GENCB_get_arg
478-
// API which is what is supposed to be used here. Older versions,
479-
// however, omit that API.
480-
// *static_cast<PrimeCheckCallback*>(BN_GENCB_get_arg(ctx));
475+
// BN_GENCB is opaque in OpenSSL 3.x, must use accessor
476+
PrimeCheckCallback& ptr =
477+
*static_cast<PrimeCheckCallback*>(BN_GENCB_get_arg(ctx));
481478
return ptr(a, b) ? 1 : 0;
482479
},
483480
&innerCb);
@@ -507,11 +504,9 @@ bool BignumPointer::generate(const PrimeConfig& params,
507504
BN_GENCB_set(
508505
cb.get(),
509506
[](int a, int b, BN_GENCB* ctx) mutable -> int {
510-
PrimeCheckCallback& ptr = *static_cast<PrimeCheckCallback*>(ctx->arg);
511-
// Newer versions of openssl and boringssl define the BN_GENCB_get_arg
512-
// API which is what is supposed to be used here. Older versions,
513-
// however, omit that API.
514-
// *static_cast<PrimeCheckCallback*>(BN_GENCB_get_arg(ctx));
507+
// BN_GENCB is opaque in OpenSSL 3.x, must use accessor
508+
PrimeCheckCallback& ptr =
509+
*static_cast<PrimeCheckCallback*>(BN_GENCB_get_arg(ctx));
515510
return ptr(a, b) ? 1 : 0;
516511
},
517512
&innerCb);

0 commit comments

Comments
 (0)