@@ -350,15 +350,15 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_openssl_encrypt, 0, 0, 3)
350350 ZEND_ARG_INFO (0 , data )
351351 ZEND_ARG_INFO (0 , method )
352352 ZEND_ARG_INFO (0 , password )
353- ZEND_ARG_INFO (0 , raw_output )
353+ ZEND_ARG_INFO (0 , options )
354354 ZEND_ARG_INFO (0 , iv )
355355ZEND_END_ARG_INFO ()
356356
357357ZEND_BEGIN_ARG_INFO_EX (arginfo_openssl_decrypt , 0 , 0 , 3 )
358358 ZEND_ARG_INFO (0 , data )
359359 ZEND_ARG_INFO (0 , method )
360360 ZEND_ARG_INFO (0 , password )
361- ZEND_ARG_INFO (0 , raw_input )
361+ ZEND_ARG_INFO (0 , options )
362362 ZEND_ARG_INFO (0 , iv )
363363ZEND_END_ARG_INFO ()
364364
@@ -1089,6 +1089,9 @@ PHP_MINIT_FUNCTION(openssl)
10891089 REGISTER_LONG_CONSTANT ("OPENSSL_KEYTYPE_EC" , OPENSSL_KEYTYPE_EC , CONST_CS |CONST_PERSISTENT );
10901090#endif
10911091
1092+ REGISTER_LONG_CONSTANT ("OPENSSL_RAW_DATA" , OPENSSL_RAW_DATA , CONST_CS |CONST_PERSISTENT );
1093+ REGISTER_LONG_CONSTANT ("OPENSSL_ZERO_PADDING" , OPENSSL_ZERO_PADDING , CONST_CS |CONST_PERSISTENT );
1094+
10921095#if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT )
10931096 /* SNI support included in OpenSSL >= 0.9.8j */
10941097 REGISTER_LONG_CONSTANT ("OPENSSL_TLSEXT_SERVER_NAME" , 1 , CONST_CS |CONST_PERSISTENT );
@@ -4679,11 +4682,11 @@ static zend_bool php_openssl_validate_iv(char **piv, int *piv_len, int iv_requir
46794682
46804683}
46814684
4682- /* {{{ proto string openssl_encrypt(string data, string method, string password [, bool raw_output=false [, string $iv='']])
4685+ /* {{{ proto string openssl_encrypt(string data, string method, string password [, long options=0 [, string $iv='']])
46834686 Encrypts given data with given method and key, returns raw or base64 encoded string */
46844687PHP_FUNCTION (openssl_encrypt )
46854688{
4686- zend_bool raw_output = 0 ;
4689+ long options = 0 ;
46874690 char * data , * method , * password , * iv = "" ;
46884691 int data_len , method_len , password_len , iv_len = 0 , max_iv_len ;
46894692 const EVP_CIPHER * cipher_type ;
@@ -4692,7 +4695,7 @@ PHP_FUNCTION(openssl_encrypt)
46924695 unsigned char * outbuf , * key ;
46934696 zend_bool free_iv ;
46944697
4695- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "sss|bs " , & data , & data_len , & method , & method_len , & password , & password_len , & raw_output , & iv , & iv_len ) == FAILURE ) {
4698+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "sss|ls " , & data , & data_len , & method , & method_len , & password , & password_len , & options , & iv , & iv_len ) == FAILURE ) {
46964699 return ;
46974700 }
46984701 cipher_type = EVP_get_cipherbyname (method );
@@ -4720,11 +4723,14 @@ PHP_FUNCTION(openssl_encrypt)
47204723 outbuf = emalloc (outlen + 1 );
47214724
47224725 EVP_EncryptInit (& cipher_ctx , cipher_type , key , (unsigned char * )iv );
4726+ if (options & OPENSSL_ZERO_PADDING ) {
4727+ EVP_CIPHER_CTX_set_padding (& cipher_ctx , 0 );
4728+ }
47234729 EVP_EncryptUpdate (& cipher_ctx , outbuf , & i , (unsigned char * )data , data_len );
47244730 outlen = i ;
47254731 if (EVP_EncryptFinal (& cipher_ctx , (unsigned char * )outbuf + i , & i )) {
47264732 outlen += i ;
4727- if (raw_output ) {
4733+ if (options & OPENSSL_RAW_DATA ) {
47284734 outbuf [outlen ] = '\0' ;
47294735 RETVAL_STRINGL ((char * )outbuf , outlen , 0 );
47304736 } else {
@@ -4749,11 +4755,11 @@ PHP_FUNCTION(openssl_encrypt)
47494755}
47504756/* }}} */
47514757
4752- /* {{{ proto string openssl_decrypt(string data, string method, string password [, bool raw_input=false [, string $iv = '']])
4758+ /* {{{ proto string openssl_decrypt(string data, string method, string password [, long options=0 [, string $iv = '']])
47534759 Takes raw or base64 encoded string and dectupt it using given method and key */
47544760PHP_FUNCTION (openssl_decrypt )
47554761{
4756- zend_bool raw_input = 0 ;
4762+ long options = 0 ;
47574763 char * data , * method , * password , * iv = "" ;
47584764 int data_len , method_len , password_len , iv_len = 0 ;
47594765 const EVP_CIPHER * cipher_type ;
@@ -4764,7 +4770,7 @@ PHP_FUNCTION(openssl_decrypt)
47644770 char * base64_str = NULL ;
47654771 zend_bool free_iv ;
47664772
4767- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "sss|bs " , & data , & data_len , & method , & method_len , & password , & password_len , & raw_input , & iv , & iv_len ) == FAILURE ) {
4773+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "sss|ls " , & data , & data_len , & method , & method_len , & password , & password_len , & options , & iv , & iv_len ) == FAILURE ) {
47684774 return ;
47694775 }
47704776
@@ -4779,7 +4785,7 @@ PHP_FUNCTION(openssl_decrypt)
47794785 RETURN_FALSE ;
47804786 }
47814787
4782- if (!raw_input ) {
4788+ if (!( options & OPENSSL_RAW_DATA ) ) {
47834789 base64_str = (char * )php_base64_decode ((unsigned char * )data , data_len , & base64_str_len );
47844790 data_len = base64_str_len ;
47854791 data = base64_str ;
@@ -4800,6 +4806,9 @@ PHP_FUNCTION(openssl_decrypt)
48004806 outbuf = emalloc (outlen + 1 );
48014807
48024808 EVP_DecryptInit (& cipher_ctx , cipher_type , key , (unsigned char * )iv );
4809+ if (options & OPENSSL_ZERO_PADDING ) {
4810+ EVP_CIPHER_CTX_set_padding (& cipher_ctx , 0 );
4811+ }
48034812 EVP_DecryptUpdate (& cipher_ctx , outbuf , & i , (unsigned char * )data , data_len );
48044813 outlen = i ;
48054814 if (EVP_DecryptFinal (& cipher_ctx , (unsigned char * )outbuf + i , & i )) {
0 commit comments