59
59
module deimos.openssl.rsa ;
60
60
61
61
import deimos.openssl._d_util;
62
+ import deimos.openssl.opensslv;
62
63
63
64
import deimos.openssl.evp; // Needed for EVP_PKEY_ALG_CTRL.
64
65
@@ -244,14 +245,44 @@ auto EVP_PKEY_CTX_get_rsa_pss_saltlen()(EVP_PKEY_CTX* ctx, int *plen) {
244
245
0 , plen);
245
246
}
246
247
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);
250
261
}
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
+ }
251
276
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
+ }
255
286
}
256
287
257
288
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);
275
306
enum EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN = (EVP_PKEY_ALG_CTRL + 7 );
276
307
enum EVP_PKEY_CTRL_GET_RSA_MGF1_MD = (EVP_PKEY_ALG_CTRL + 8 );
277
308
309
+ static if (OPENSSL_VERSION_AT_LEAST (1 , 1 , 1 ))
310
+ enum EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES = (EVP_PKEY_ALG_CTRL + 13 );
311
+
278
312
enum RSA_PKCS1_PADDING = 1 ;
279
313
enum RSA_SSLV23_PADDING = 2 ;
280
314
enum RSA_NO_PADDING = 3 ;
0 commit comments