Skip to content

Commit 032ed63

Browse files
committed
pkey: define and use OSSL_HAVE_IMMUTABLE_PKEY macro
Introduce a useful macro indicating that the low-level struct wrapped in an EVP_PKEY cannot be modified. Currently, the macro is defined for OpenSSL 3.0 or later only. LibreSSL and AWS-LC can follow suit in the future.
1 parent 4b923b4 commit 032ed63

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

ext/openssl/ossl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
# include <openssl/provider.h>
7575
#endif
7676

77+
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
78+
# define OSSL_HAVE_IMMUTABLE_PKEY
79+
#endif
80+
7781
/*
7882
* Common Module
7983
*/

ext/openssl/ossl_pkey.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ ossl_pkey_s_generate_key(int argc, VALUE *argv, VALUE self)
508508
void
509509
ossl_pkey_check_public_key(const EVP_PKEY *pkey)
510510
{
511-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
511+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
512512
if (EVP_PKEY_missing_parameters(pkey))
513513
ossl_raise(ePKeyError, "parameters missing");
514514
#else

ext/openssl/ossl_pkey.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static VALUE ossl_##_keytype##_get_##_name(VALUE self) \
105105
OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a2, \
106106
_type##_get0_##_group(obj, NULL, &bn))
107107

108-
#if !OSSL_OPENSSL_PREREQ(3, 0, 0)
108+
#ifndef OSSL_HAVE_IMMUTABLE_PKEY
109109
#define OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3) \
110110
/* \
111111
* call-seq: \

ext/openssl/ossl_pkey_ec.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ ossl_ec_key_get_group(VALUE self)
246246
static VALUE
247247
ossl_ec_key_set_group(VALUE self, VALUE group_v)
248248
{
249-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
249+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
250250
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
251251
#else
252252
EC_KEY *ec;
@@ -288,7 +288,7 @@ static VALUE ossl_ec_key_get_private_key(VALUE self)
288288
*/
289289
static VALUE ossl_ec_key_set_private_key(VALUE self, VALUE private_key)
290290
{
291-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
291+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
292292
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
293293
#else
294294
EC_KEY *ec;
@@ -339,7 +339,7 @@ static VALUE ossl_ec_key_get_public_key(VALUE self)
339339
*/
340340
static VALUE ossl_ec_key_set_public_key(VALUE self, VALUE public_key)
341341
{
342-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
342+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
343343
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
344344
#else
345345
EC_KEY *ec;
@@ -511,7 +511,7 @@ ossl_ec_key_to_der(VALUE self)
511511
*/
512512
static VALUE ossl_ec_key_generate_key(VALUE self)
513513
{
514-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
514+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
515515
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
516516
#else
517517
EC_KEY *ec;
@@ -1368,7 +1368,7 @@ static VALUE ossl_ec_point_make_affine(VALUE self)
13681368
GetECPointGroup(self, group);
13691369

13701370
rb_warn("OpenSSL::PKey::EC::Point#make_affine! is deprecated");
1371-
#if !OSSL_OPENSSL_PREREQ(3, 0, 0) && !defined(OPENSSL_IS_AWSLC)
1371+
#if !defined(OSSL_HAVE_IMMUTABLE_PKEY) && !defined(OPENSSL_IS_AWSLC)
13721372
if (EC_POINT_make_affine(group, point, ossl_bn_ctx) != 1)
13731373
ossl_raise(eEC_POINT, "EC_POINT_make_affine");
13741374
#endif

0 commit comments

Comments
 (0)