Skip to content

Commit 2540f68

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Allow passing $tag for non-authenticated encryption
2 parents 06bb1fe + 6c6a58e commit 2540f68

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

ext/openssl/openssl.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7156,8 +7156,6 @@ PHP_OPENSSL_API zend_string* php_openssl_encrypt(
71567156
}
71577157
} else if (tag) {
71587158
ZEND_TRY_ASSIGN_REF_NULL(tag);
7159-
php_error_docref(NULL, E_WARNING,
7160-
"The authenticated tag cannot be provided for cipher that doesn not support AEAD");
71617159
} else if (mode.is_aead) {
71627160
php_error_docref(NULL, E_WARNING, "A tag should be provided when using AEAD mode");
71637161
zend_string_release_ex(outbuf, 0);

ext/openssl/tests/openssl_decrypt_basic.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ var_dump(rtrim($output));
2828
$encrypted = openssl_encrypt($data, "bf-ecb", $password, OPENSSL_DONT_ZERO_PAD_KEY);
2929
$output = openssl_decrypt($encrypted, "bf-ecb", $password, OPENSSL_DONT_ZERO_PAD_KEY);
3030
var_dump($output);
31+
32+
// It's okay to pass $tag for a non-authenticated cipher.
33+
// It will be populated with null in that case.
34+
openssl_encrypt($data, $method, $password, 0, $iv, $tag);
35+
var_dump($tag);
36+
3137
?>
3238
--EXPECT--
3339
string(45) "openssl_encrypt() and openssl_decrypt() tests"
3440
string(45) "openssl_encrypt() and openssl_decrypt() tests"
3541
string(45) "openssl_encrypt() and openssl_decrypt() tests"
3642
string(45) "openssl_encrypt() and openssl_decrypt() tests"
43+
NULL

ext/openssl/tests/openssl_decrypt_error.phpt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ var_dump(openssl_decrypt($wrong, $wrong, $password));
2020
var_dump(openssl_decrypt($encrypted, $wrong, $wrong));
2121
var_dump(openssl_decrypt($wrong, $wrong, $wrong));
2222

23-
// invalid using of an authentication tag
24-
var_dump(openssl_encrypt($data, $method, $password, 0, $iv, $wrong));
2523
?>
2624
--EXPECTF--
2725
Warning: openssl_encrypt(): Using an empty Initialization Vector (iv) is potentially insecure and not recommended in %s on line %d
@@ -41,6 +39,3 @@ bool(false)
4139

4240
Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
4341
bool(false)
44-
45-
Warning: openssl_encrypt(): The authenticated tag cannot be provided for cipher that doesn not support AEAD in %s on line %d
46-
string(44) "yof6cPPH4mLee6TOc0YQSrh4dvywMqxGUyjp0lV6+aM="

ext/openssl/tests/openssl_encrypt_error.phpt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,12 @@ $arr = array(1);
1515
// wrong parameters tests
1616
var_dump(openssl_encrypt($data, $wrong, $password));
1717

18-
// invalid using of an authentication tag
19-
var_dump(openssl_encrypt($data, $method, $password, 0, $iv, $wrong));
20-
2118
// padding of the key is disabled
2219
var_dump(openssl_encrypt($data, $method, $password, OPENSSL_DONT_ZERO_PAD_KEY, $iv));
2320
?>
2421
--EXPECTF--
2522
Warning: openssl_encrypt(): Unknown cipher algorithm in %s on line %d
2623
bool(false)
2724

28-
Warning: openssl_encrypt(): The authenticated tag cannot be provided for cipher that doesn not support AEAD in %s on line %d
29-
string(44) "iPR4HulskuaP5Z6me5uImk6BqVyJG73+63tkPauVZYk="
30-
3125
Warning: openssl_encrypt(): Key length cannot be set for the cipher algorithm in %s on line %d
3226
bool(false)

0 commit comments

Comments
 (0)