com php-src: Add AEAD IV init: ext/openssl/openssl.c
| From: | Jakub Zelenka | Date: | Tue, 01 Dec 2015 19:34:12 +0000 |
| Subject: | com php-src: Add AEAD IV init: ext/openssl/openssl.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92495@lists.php.net to get a copy of this message | ||
Commit: c9931511156c49def263e6f2b1ec3a4f3d83e1f8
Author: Jakub Zelenka <bukka@php.net> Tue, 1 Dec 2015 19:34:12 +0000
Parents: 55b5160295ebb5a0f7cb224fef83ada161c1779e
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c9931511156c49def263e6f2b1ec3a4f3d83e1f8
Log:
Add AEAD IV init
Changed paths:
M ext/openssl/openssl.c
Diff:
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 0562b6b..465d3b3 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -5230,7 +5230,8 @@ static void php_openssl_load_cipher_mode(struct php_openssl_cipher_mode *mode,
c
}
/* }}} */
-static int php_openssl_validate_iv(char **piv, size_t *piv_len, size_t iv_required_len, zend_bool
*free_iv) /* {{{ */
+static int php_openssl_validate_iv(char **piv, size_t *piv_len, size_t iv_required_len,
+ zend_bool *free_iv, EVP_CIPHER_CTX *cipher_ctx, struct php_openssl_cipher_mode *mode) /* {{{ */
{
char *iv_new;
@@ -5239,6 +5240,16 @@ static int php_openssl_validate_iv(char **piv, size_t *piv_len, size_t
iv_requir
return SUCCESS;
}
+ if (mode->is_aead) {
+ if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_ivlen_flag, *piv_len, NULL) != 1) {
+ php_error_docref(NULL, E_WARNING,
+ "Setting of IV length for AEAD mode failed, the expected length is %d bytes",
+ iv_required_len);
+ return FAILURE;
+ }
+ return SUCCESS;
+ }
+
iv_new = ecalloc(1, iv_required_len + 1);
if (*piv_len == 0) {
@@ -5250,7 +5261,9 @@ static int php_openssl_validate_iv(char **piv, size_t *piv_len, size_t
iv_requir
}
if (*piv_len < iv_required_len) {
- php_error_docref(NULL, E_WARNING, "IV passed is only %d bytes long, cipher expects an IV of
precisely %d bytes, padding with \\0", *piv_len, iv_required_len);
+ php_error_docref(NULL, E_WARNING,
+ "IV passed is only %d bytes long, cipher expects an IV of precisely %d bytes, padding with
\\0",
+ *piv_len, iv_required_len);
memcpy(iv_new, *piv, *piv_len);
*piv_len = iv_required_len;
*piv = iv_new;
@@ -5258,7 +5271,9 @@ static int php_openssl_validate_iv(char **piv, size_t *piv_len, size_t
iv_requir
return SUCCESS;
}
- php_error_docref(NULL, E_WARNING, "IV passed is %d bytes long which is longer than the %d
expected by selected cipher, truncating", *piv_len, iv_required_len);
+ php_error_docref(NULL, E_WARNING,
+ "IV passed is %d bytes long which is longer than the %d expected by selected cipher,
truncating",
+ *piv_len, iv_required_len);
memcpy(iv_new, *piv, iv_required_len);
*piv_len = iv_required_len;
*piv = iv_new;
@@ -5298,13 +5313,13 @@ static int php_openssl_cipher_init(const EVP_CIPHER *cipher_type,
php_error_docref(NULL, E_WARNING,
"Using an empty Initialization Vector (iv) is potentially insecure and not
recommended");
}
- if (php_openssl_validate_iv(piv, piv_len, max_iv_len, free_iv) == FAILURE) {
- return FAILURE;
- }
if (!EVP_CipherInit_ex(cipher_ctx, cipher_type, NULL, NULL, NULL, enc)) {
return FAILURE;
}
+ if (php_openssl_validate_iv(piv, piv_len, max_iv_len, free_iv, cipher_ctx, mode) == FAILURE) {
+ return FAILURE;
+ }
if (password_len > key_len) {
EVP_CIPHER_CTX_set_key_length(cipher_ctx, password_len);
}