com php-src: Set AEAD tag or tag_len if supplied: ext /openssl/openssl.c
| From: | Jakub Zelenka | Date: | Thu, 03 Dec 2015 19:16:11 +0000 |
| Subject: | com php-src: Set AEAD tag or tag_len if supplied: ext /openssl/openssl.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92487@lists.php.net to get a copy of this message | ||
Commit: e74368a8a196fdb590cfd23ca4062c5e79e0d061
Author: Jakub Zelenka <bukka@php.net> Thu, 3 Dec 2015 19:16:11 +0000
Parents: c9931511156c49def263e6f2b1ec3a4f3d83e1f8
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e74368a8a196fdb590cfd23ca4062c5e79e0d061
Log:
Set AEAD tag or tag_len if supplied
Changed paths:
M ext/openssl/openssl.c
Diff:
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 465d3b3..fbf6a32 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -5287,7 +5287,7 @@ static int php_openssl_cipher_init(const EVP_CIPHER *cipher_type,
EVP_CIPHER_CTX *cipher_ctx, struct php_openssl_cipher_mode *mode,
char **ppassword, size_t *ppassword_len, zend_bool *free_password,
char **piv, size_t *piv_len, zend_bool *free_iv,
- zend_long options, int enc) /* {{{ */
+ char *tag, int tag_len, zend_long options, int enc) /* {{{ */
{
unsigned char *key;
int key_len, password_len;
@@ -5320,6 +5320,13 @@ static int php_openssl_cipher_init(const EVP_CIPHER *cipher_type,
if (php_openssl_validate_iv(piv, piv_len, max_iv_len, free_iv, cipher_ctx, mode) == FAILURE) {
return FAILURE;
}
+ if (mode->is_single_run_aead && enc) {
+ EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_set_tag_flag, tag_len, NULL);
+ } else if (!enc && mode->is_aead && tag &&
+ !EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_set_tag_flag, tag_len, (unsigned char *) tag)) {
+ php_error_docref(NULL, E_WARNING, "Setting tag for AEAD cipher encryption failed");
+ return FAILURE;
+ }
if (password_len > key_len) {
EVP_CIPHER_CTX_set_key_length(cipher_ctx, password_len);
}
@@ -5375,7 +5382,7 @@ PHP_FUNCTION(openssl_encrypt)
if (php_openssl_cipher_init(cipher_type, cipher_ctx, &mode,
&password, &password_len, &free_password,
- &iv, &iv_len, &free_iv, options, 1) == FAILURE) {
+ &iv, &iv_len, &free_iv, NULL, tag_len, options, 1) == FAILURE) {
RETVAL_FALSE;
goto openssl_encrypt_clean;
}
@@ -5421,7 +5428,7 @@ openssl_encrypt_clean:
PHP_FUNCTION(openssl_decrypt)
{
zend_long options = 0;
- char *data, *method, *password, *iv = "", *tag = "", *aad = "";
+ char *data, *method, *password, *iv = "", *tag = NULL, *aad = "";
size_t data_len, method_len, password_len, iv_len = 0, tag_len = 0, aad_len = 0;
const EVP_CIPHER *cipher_type;
EVP_CIPHER_CTX *cipher_ctx;
@@ -5473,7 +5480,7 @@ PHP_FUNCTION(openssl_decrypt)
if (php_openssl_cipher_init(cipher_type, cipher_ctx, &mode,
&password, &password_len, &free_password,
- &iv, &iv_len, &free_iv, options, 0) == FAILURE) {
+ &iv, &iv_len, &free_iv, tag, tag_len, options, 0) == FAILURE) {
php_error_docref(NULL, E_WARNING, "Failed to initialize cipher decryption");
RETVAL_FALSE;
goto openssl_decrypt_clean;