Skip to content

Commit 2194ad8

Browse files
committed
Make further OpenSSL 1.0.2 clean up
Closes GH-18133
1 parent f146974 commit 2194ad8

8 files changed

+7
-215
lines changed

ext/openssl/openssl.c

-15
Original file line numberDiff line numberDiff line change
@@ -3975,20 +3975,11 @@ PHP_FUNCTION(openssl_sign)
39753975

39763976
md_ctx = EVP_MD_CTX_create();
39773977
size_t siglen;
3978-
#if PHP_OPENSSL_API_VERSION >= 0x10100
39793978
if (md_ctx != NULL &&
39803979
EVP_DigestSignInit(md_ctx, NULL, mdtype, NULL, pkey) &&
39813980
EVP_DigestSign(md_ctx, NULL, &siglen, (unsigned char*)data, data_len) &&
39823981
(sigbuf = zend_string_alloc(siglen, 0)) != NULL &&
39833982
EVP_DigestSign(md_ctx, (unsigned char*)ZSTR_VAL(sigbuf), &siglen, (unsigned char*)data, data_len)) {
3984-
#else
3985-
if (md_ctx != NULL &&
3986-
EVP_SignInit(md_ctx, mdtype) &&
3987-
EVP_SignUpdate(md_ctx, data, data_len) &&
3988-
(siglen = EVP_PKEY_size(pkey)) &&
3989-
(sigbuf = zend_string_alloc(siglen, 0)) != NULL &&
3990-
EVP_SignFinal(md_ctx, (unsigned char*)ZSTR_VAL(sigbuf), (unsigned int*)&siglen, pkey)) {
3991-
#endif
39923983
ZSTR_VAL(sigbuf)[siglen] = '\0';
39933984
ZSTR_LEN(sigbuf) = siglen;
39943985
ZEND_TRY_ASSIGN_REF_NEW_STR(signature, sigbuf);
@@ -4049,14 +4040,8 @@ PHP_FUNCTION(openssl_verify)
40494040

40504041
md_ctx = EVP_MD_CTX_create();
40514042
if (md_ctx == NULL ||
4052-
#if PHP_OPENSSL_API_VERSION >= 0x10100
40534043
!EVP_DigestVerifyInit(md_ctx, NULL, mdtype, NULL, pkey) ||
40544044
(err = EVP_DigestVerify(md_ctx, (unsigned char *)signature, signature_len, (unsigned char*)data, data_len)) < 0) {
4055-
#else
4056-
!EVP_VerifyInit (md_ctx, mdtype) ||
4057-
!EVP_VerifyUpdate (md_ctx, data, data_len) ||
4058-
(err = EVP_VerifyFinal(md_ctx, (unsigned char *)signature, (unsigned int)signature_len, pkey)) < 0) {
4059-
#endif
40604045
php_openssl_store_errors();
40614046
}
40624047
EVP_MD_CTX_destroy(md_ctx);

ext/openssl/openssl.stub.php

-8
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,6 @@
8686
*/
8787
const OPENSSL_ALGO_MD2 = UNKNOWN;
8888
#endif
89-
#if PHP_OPENSSL_API_VERSION < 0x10100
90-
/**
91-
* @var int
92-
* @cvalue OPENSSL_ALGO_DSS1
93-
*/
94-
const OPENSSL_ALGO_DSS1 = UNKNOWN;
95-
#endif
96-
9789
/**
9890
* @var int
9991
* @cvalue OPENSSL_ALGO_SHA224

ext/openssl/openssl_arginfo.h

+1-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/openssl/openssl_backend_common.c

+4-35
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ zend_result php_openssl_write_rand_file(const char * file, int egdsocket, int se
461461
if (file == NULL) {
462462
file = RAND_file_name(buffer, sizeof(buffer));
463463
}
464-
PHP_OPENSSL_RAND_ADD_TIME();
465464
if (file == NULL || !RAND_write_file(file)) {
466465
php_openssl_store_errors();
467466
php_error_docref(NULL, E_WARNING, "Unable to write random state");
@@ -489,11 +488,6 @@ EVP_MD * php_openssl_get_evp_md_from_algo(zend_long algo) {
489488
case OPENSSL_ALGO_MD2:
490489
mdtype = (EVP_MD *) EVP_md2();
491490
break;
492-
#endif
493-
#if PHP_OPENSSL_API_VERSION < 0x10100
494-
case OPENSSL_ALGO_DSS1:
495-
mdtype = (EVP_MD *) EVP_dss1();
496-
break;
497491
#endif
498492
case OPENSSL_ALGO_SHA224:
499493
mdtype = (EVP_MD *) EVP_sha224();
@@ -1510,7 +1504,6 @@ EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req)
15101504
int egdsocket, seeded;
15111505
char *randfile = php_openssl_conf_get_string(req->req_config, req->section_name, "RANDFILE");
15121506
php_openssl_load_rand_file(randfile, &egdsocket, &seeded);
1513-
PHP_OPENSSL_RAND_ADD_TIME();
15141507

15151508
EVP_PKEY *key = NULL;
15161509
EVP_PKEY *params = NULL;
@@ -1700,48 +1693,25 @@ void php_openssl_load_cipher_mode(struct php_openssl_cipher_mode *mode, const EV
17001693
int cipher_mode = EVP_CIPHER_mode(cipher_type);
17011694
memset(mode, 0, sizeof(struct php_openssl_cipher_mode));
17021695
switch (cipher_mode) {
1703-
#if PHP_OPENSSL_API_VERSION >= 0x10100
1704-
/* Since OpenSSL 1.1, all AEAD ciphers use a common framework. We check for
1705-
* EVP_CIPH_OCB_MODE, because LibreSSL does not support it. */
17061696
case EVP_CIPH_GCM_MODE:
17071697
case EVP_CIPH_CCM_MODE:
1708-
# ifdef EVP_CIPH_OCB_MODE
1698+
/* We check for EVP_CIPH_OCB_MODE, because LibreSSL does not support it. */
1699+
#ifdef EVP_CIPH_OCB_MODE
17091700
case EVP_CIPH_OCB_MODE:
17101701
/* For OCB mode, explicitly set the tag length even when decrypting,
17111702
* see https://github.com/openssl/openssl/issues/8331. */
17121703
mode->set_tag_length_always = cipher_mode == EVP_CIPH_OCB_MODE;
1713-
# endif
1704+
#endif
17141705
php_openssl_set_aead_flags(mode);
17151706
mode->set_tag_length_when_encrypting = cipher_mode == EVP_CIPH_CCM_MODE;
17161707
mode->is_single_run_aead = cipher_mode == EVP_CIPH_CCM_MODE;
17171708
break;
1718-
# ifdef NID_chacha20_poly1305
1709+
#ifdef NID_chacha20_poly1305
17191710
default:
17201711
if (EVP_CIPHER_nid(cipher_type) == NID_chacha20_poly1305) {
17211712
php_openssl_set_aead_flags(mode);
17221713
}
17231714
break;
1724-
1725-
# endif
1726-
#else
1727-
# ifdef EVP_CIPH_GCM_MODE
1728-
case EVP_CIPH_GCM_MODE:
1729-
mode->is_aead = 1;
1730-
mode->aead_get_tag_flag = EVP_CTRL_GCM_GET_TAG;
1731-
mode->aead_set_tag_flag = EVP_CTRL_GCM_SET_TAG;
1732-
mode->aead_ivlen_flag = EVP_CTRL_GCM_SET_IVLEN;
1733-
break;
1734-
# endif
1735-
# ifdef EVP_CIPH_CCM_MODE
1736-
case EVP_CIPH_CCM_MODE:
1737-
mode->is_aead = 1;
1738-
mode->is_single_run_aead = 1;
1739-
mode->set_tag_length_when_encrypting = 1;
1740-
mode->aead_get_tag_flag = EVP_CTRL_CCM_GET_TAG;
1741-
mode->aead_set_tag_flag = EVP_CTRL_CCM_SET_TAG;
1742-
mode->aead_ivlen_flag = EVP_CTRL_CCM_SET_IVLEN;
1743-
break;
1744-
# endif
17451715
#endif
17461716
}
17471717
}
@@ -2121,7 +2091,6 @@ PHP_OPENSSL_API zend_string* php_openssl_random_pseudo_bytes(zend_long buffer_le
21212091
buffer = zend_string_alloc(buffer_length, 0);
21222092

21232093
PHP_OPENSSL_CHECK_LONG_TO_INT_NULL_RETURN(buffer_length, length);
2124-
PHP_OPENSSL_RAND_ADD_TIME();
21252094
if (RAND_bytes((unsigned char*)ZSTR_VAL(buffer), (int)buffer_length) <= 0) {
21262095
php_openssl_store_errors();
21272096
zend_string_release_ex(buffer, 0);

ext/openssl/openssl_backend_v1.c

-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ static bool php_openssl_pkey_init_dsa_data(DSA *dsa, zval *data, bool *is_privat
116116
}
117117

118118
/* generate key */
119-
PHP_OPENSSL_RAND_ADD_TIME();
120119
if (!DSA_generate_key(dsa)) {
121120
php_openssl_store_errors();
122121
return 0;
@@ -185,7 +184,6 @@ static bool php_openssl_pkey_init_dh_data(DH *dh, zval *data, bool *is_private)
185184
}
186185

187186
/* generate key */
188-
PHP_OPENSSL_RAND_ADD_TIME();
189187
if (!DH_generate_key(dh)) {
190188
php_openssl_store_errors();
191189
return 0;
@@ -341,7 +339,6 @@ static bool php_openssl_pkey_init_ec_data(EC_KEY *eckey, zval *data, bool *is_pr
341339

342340
if (!EC_KEY_check_key(eckey)) {
343341
*is_private = true;
344-
PHP_OPENSSL_RAND_ADD_TIME();
345342
EC_KEY_generate_key(eckey);
346343
}
347344

ext/openssl/openssl_backend_v3.c

-4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ EVP_PKEY *php_openssl_pkey_init_dsa(zval *data, bool *is_private)
143143
pkey = param_key;
144144
} else {
145145
*is_private = true;
146-
PHP_OPENSSL_RAND_ADD_TIME();
147146
EVP_PKEY_CTX_free(ctx);
148147
ctx = EVP_PKEY_CTX_new(param_key, NULL);
149148
if (EVP_PKEY_keygen_init(ctx) <= 0 || EVP_PKEY_keygen(ctx, &pkey) <= 0) {
@@ -219,7 +218,6 @@ EVP_PKEY *php_openssl_pkey_init_dh(zval *data, bool *is_private)
219218
pkey = param_key;
220219
} else {
221220
*is_private = true;
222-
PHP_OPENSSL_RAND_ADD_TIME();
223221
EVP_PKEY_CTX_free(ctx);
224222
ctx = EVP_PKEY_CTX_new(param_key, NULL);
225223
if (EVP_PKEY_keygen_init(ctx) <= 0 || EVP_PKEY_keygen(ctx, &pkey) <= 0) {
@@ -407,7 +405,6 @@ EVP_PKEY *php_openssl_pkey_init_ec(zval *data, bool *is_private) {
407405
pkey = param_key;
408406
} else {
409407
*is_private = true;
410-
PHP_OPENSSL_RAND_ADD_TIME();
411408
if (EVP_PKEY_keygen_init(ctx) != 1 ||
412409
EVP_PKEY_CTX_set_params(ctx, params) != 1 ||
413410
EVP_PKEY_generate(ctx, &pkey) != 1) {
@@ -482,7 +479,6 @@ void php_openssl_pkey_object_curve_25519_448(zval *return_value, int key_type, z
482479
is_private = priv_key != NULL;
483480
} else {
484481
is_private = true;
485-
PHP_OPENSSL_RAND_ADD_TIME();
486482
if (EVP_PKEY_keygen_init(ctx) <= 0 || EVP_PKEY_keygen(ctx, &pkey) <= 0) {
487483
goto cleanup;
488484
}

ext/openssl/php_openssl_backend.h

+2-25
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ enum php_openssl_encoding {
118118
#ifndef OPENSSL_NO_MD2
119119
#define OPENSSL_ALGO_MD2 4
120120
#endif
121-
#if PHP_OPENSSL_API_VERSION < 0x10100
122-
#define OPENSSL_ALGO_DSS1 5
123-
#endif
121+
/* Number 5 was used for OPENSSL_ALGO_DSS1 which is no longer available */
124122
#define OPENSSL_ALGO_SHA224 6
125123
#define OPENSSL_ALGO_SHA256 7
126124
#define OPENSSL_ALGO_SHA384 8
@@ -220,23 +218,6 @@ const EVP_CIPHER * php_openssl_get_evp_cipher_from_algo(zend_long algo);
220218
int php_openssl_parse_config(struct php_x509_request * req, zval * optional_args);
221219
void php_openssl_dispose_config(struct php_x509_request * req);
222220

223-
224-
#if defined(PHP_WIN32) || PHP_OPENSSL_API_VERSION >= 0x10100
225-
#define PHP_OPENSSL_RAND_ADD_TIME() ((void) 0)
226-
#else
227-
#define PHP_OPENSSL_RAND_ADD_TIME() php_openssl_rand_add_timeval()
228-
229-
static inline void php_openssl_rand_add_timeval(void) /* {{{ */
230-
{
231-
struct timeval tv;
232-
233-
gettimeofday(&tv, NULL);
234-
RAND_add(&tv, sizeof(tv), 0.0);
235-
}
236-
/* }}} */
237-
238-
#endif
239-
240221
zend_result php_openssl_load_rand_file(const char * file, int *egdsocket, int *seeded);
241222
zend_result php_openssl_write_rand_file(const char * file, int egdsocket, int seeded);
242223

@@ -279,7 +260,7 @@ X509_REQ *php_openssl_csr_from_str(zend_string *csr_str, uint32_t arg_num);
279260
X509_REQ *php_openssl_csr_from_param(
280261
zend_object *csr_obj, zend_string *csr_str, uint32_t arg_num);
281262

282-
#if PHP_OPENSSL_API_VERSION >= 0x10100 && !defined (LIBRESSL_VERSION_NUMBER)
263+
#if !defined (LIBRESSL_VERSION_NUMBER)
283264
#define PHP_OPENSSL_ASN1_INTEGER_set ASN1_INTEGER_set_int64
284265
#else
285266
#define PHP_OPENSSL_ASN1_INTEGER_set ASN1_INTEGER_set
@@ -349,14 +330,12 @@ struct php_openssl_cipher_mode {
349330
int aead_ivlen_flag;
350331
};
351332

352-
#if PHP_OPENSSL_API_VERSION >= 0x10100
353333
static inline void php_openssl_set_aead_flags(struct php_openssl_cipher_mode *mode) {
354334
mode->is_aead = true;
355335
mode->aead_get_tag_flag = EVP_CTRL_AEAD_GET_TAG;
356336
mode->aead_set_tag_flag = EVP_CTRL_AEAD_SET_TAG;
357337
mode->aead_ivlen_flag = EVP_CTRL_AEAD_SET_IVLEN;
358338
}
359-
#endif
360339

361340
void php_openssl_load_cipher_mode(struct php_openssl_cipher_mode *mode, const EVP_CIPHER *cipher_type);
362341
zend_result php_openssl_validate_iv(const char **piv, size_t *piv_len, size_t iv_required_len,
@@ -375,6 +354,4 @@ zend_result php_openssl_cipher_update(const EVP_CIPHER *cipher_type,
375354

376355
const EVP_CIPHER *php_openssl_get_evp_cipher_by_name(const char *method);
377356

378-
379357
#endif
380-

0 commit comments

Comments
 (0)