Skip to content

Commit dee7592

Browse files
committed
rsa: EVP_PKEY_CTX_set_rsa_keygen_* are no longer macros in v3.0.0, add _primes
As noted in the comments, those three functions were changed from macros to actual function in v3.0.0, and [...]_pubexp was deprecated. Additionally, the bindings were previously missing the [...]_primes function, which was a macro in previous version, so it has been added.
1 parent 2a262bf commit dee7592

File tree

1 file changed

+40
-6
lines changed
  • source/deimos/openssl

1 file changed

+40
-6
lines changed

source/deimos/openssl/rsa.d

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
module deimos.openssl.rsa;
6060

6161
import deimos.openssl._d_util;
62+
import deimos.openssl.opensslv;
6263

6364
import deimos.openssl.evp; // Needed for EVP_PKEY_ALG_CTRL.
6465

@@ -244,14 +245,44 @@ auto EVP_PKEY_CTX_get_rsa_pss_saltlen()(EVP_PKEY_CTX* ctx, int *plen) {
244245
0, plen);
245246
}
246247

247-
auto EVP_PKEY_CTX_set_rsa_keygen_bits()(EVP_PKEY_CTX* ctx, int bits) {
248-
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN,
249-
EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, null);
248+
static if (OPENSSL_VERSION_AT_LEAST(3, 0, 0))
249+
{
250+
// v3.0.0 deprecated `EVP_PKEY_CTX_set_rsa_keygen_pubexp` and introduced
251+
// a `[...]set1[...]` alternative:
252+
// https://github.com/openssl/openssl/commit/3786d74868fe440250f902ce1a78974136ca9304
253+
// This is for forward compatibility: Old code still works with new OpenSSL version
254+
alias EVP_PKEY_CTX_set_rsa_keygen_pubexp = EVP_PKEY_CTX_set1_rsa_keygen_pubexp;
255+
256+
// Before v3.0.0, those functions were macros (including above deprecated one):
257+
// https://github.com/openssl/openssl/commit/2972af109e10c5ce30e548190e3eee28327d6043
258+
int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX* ctx, int bits);
259+
int EVP_PKEY_CTX_set1_rsa_keygen_pubexp(EVP_PKEY_CTX* ctx, void* pubexp);
260+
int EVP_PKEY_CTX_set_rsa_keygen_primes(EVP_PKEY_CTX* ctx, int primes);
250261
}
262+
else
263+
{
264+
// Forward compatibility alias: Code written for v3.0.0 works with v1.1.1 and below
265+
alias EVP_PKEY_CTX_set1_rsa_keygen_pubexp = EVP_PKEY_CTX_set_rsa_keygen_pubexp;
266+
267+
auto EVP_PKEY_CTX_set_rsa_keygen_bits()(EVP_PKEY_CTX* ctx, int bits) {
268+
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN,
269+
EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, null);
270+
}
271+
272+
auto EVP_PKEY_CTX_set_rsa_keygen_pubexp()(EVP_PKEY_CTX* ctx, void* pubexp) {
273+
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN,
274+
EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp);
275+
}
251276

252-
auto EVP_PKEY_CTX_set_rsa_keygen_pubexp()(EVP_PKEY_CTX* ctx, void* pubexp) {
253-
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN,
254-
EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp);
277+
static if (OPENSSL_VERSION_AT_LEAST(1, 1, 1))
278+
{
279+
// Multi-prime RSA (RFC 8017), introduced in v1.1.1:
280+
// https://github.com/openssl/openssl/commit/665d899fa6d3571da016925067ebcf1789d7d19c
281+
auto EVP_PKEY_CTX_set_rsa_keygen_primes()(EVP_PKEY_CTX* ctx, int primes) {
282+
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN,
283+
EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES, primes, null);
284+
}
285+
}
255286
}
256287

257288
auto EVP_PKEY_CTX_set_rsa_mgf1_md()(EVP_PKEY_CTX* ctx, EVP_MD* md) {
@@ -275,6 +306,9 @@ enum EVP_PKEY_CTRL_GET_RSA_PADDING = (EVP_PKEY_ALG_CTRL + 6);
275306
enum EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN = (EVP_PKEY_ALG_CTRL + 7);
276307
enum EVP_PKEY_CTRL_GET_RSA_MGF1_MD = (EVP_PKEY_ALG_CTRL + 8);
277308

309+
static if (OPENSSL_VERSION_AT_LEAST(1, 1, 1))
310+
enum EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES = (EVP_PKEY_ALG_CTRL + 13);
311+
278312
enum RSA_PKCS1_PADDING = 1;
279313
enum RSA_SSLV23_PADDING = 2;
280314
enum RSA_NO_PADDING = 3;

0 commit comments

Comments
 (0)