@@ -350,15 +350,15 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_openssl_encrypt, 0, 0, 3)
350
350
ZEND_ARG_INFO (0 , data )
351
351
ZEND_ARG_INFO (0 , method )
352
352
ZEND_ARG_INFO (0 , password )
353
- ZEND_ARG_INFO (0 , raw_output )
353
+ ZEND_ARG_INFO (0 , options )
354
354
ZEND_ARG_INFO (0 , iv )
355
355
ZEND_END_ARG_INFO ()
356
356
357
357
ZEND_BEGIN_ARG_INFO_EX (arginfo_openssl_decrypt , 0 , 0 , 3 )
358
358
ZEND_ARG_INFO (0 , data )
359
359
ZEND_ARG_INFO (0 , method )
360
360
ZEND_ARG_INFO (0 , password )
361
- ZEND_ARG_INFO (0 , raw_input )
361
+ ZEND_ARG_INFO (0 , options )
362
362
ZEND_ARG_INFO (0 , iv )
363
363
ZEND_END_ARG_INFO ()
364
364
@@ -1089,6 +1089,9 @@ PHP_MINIT_FUNCTION(openssl)
1089
1089
REGISTER_LONG_CONSTANT ("OPENSSL_KEYTYPE_EC" , OPENSSL_KEYTYPE_EC , CONST_CS |CONST_PERSISTENT );
1090
1090
#endif
1091
1091
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
+
1092
1095
#if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT )
1093
1096
/* SNI support included in OpenSSL >= 0.9.8j */
1094
1097
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
4679
4682
4680
4683
}
4681
4684
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='']])
4683
4686
Encrypts given data with given method and key, returns raw or base64 encoded string */
4684
4687
PHP_FUNCTION (openssl_encrypt )
4685
4688
{
4686
- zend_bool raw_output = 0 ;
4689
+ long options = 0 ;
4687
4690
char * data , * method , * password , * iv = "" ;
4688
4691
int data_len , method_len , password_len , iv_len = 0 , max_iv_len ;
4689
4692
const EVP_CIPHER * cipher_type ;
@@ -4692,7 +4695,7 @@ PHP_FUNCTION(openssl_encrypt)
4692
4695
unsigned char * outbuf , * key ;
4693
4696
zend_bool free_iv ;
4694
4697
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 ) {
4696
4699
return ;
4697
4700
}
4698
4701
cipher_type = EVP_get_cipherbyname (method );
@@ -4720,11 +4723,14 @@ PHP_FUNCTION(openssl_encrypt)
4720
4723
outbuf = emalloc (outlen + 1 );
4721
4724
4722
4725
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
+ }
4723
4729
EVP_EncryptUpdate (& cipher_ctx , outbuf , & i , (unsigned char * )data , data_len );
4724
4730
outlen = i ;
4725
4731
if (EVP_EncryptFinal (& cipher_ctx , (unsigned char * )outbuf + i , & i )) {
4726
4732
outlen += i ;
4727
- if (raw_output ) {
4733
+ if (options & OPENSSL_RAW_DATA ) {
4728
4734
outbuf [outlen ] = '\0' ;
4729
4735
RETVAL_STRINGL ((char * )outbuf , outlen , 0 );
4730
4736
} else {
@@ -4749,11 +4755,11 @@ PHP_FUNCTION(openssl_encrypt)
4749
4755
}
4750
4756
/* }}} */
4751
4757
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 = '']])
4753
4759
Takes raw or base64 encoded string and dectupt it using given method and key */
4754
4760
PHP_FUNCTION (openssl_decrypt )
4755
4761
{
4756
- zend_bool raw_input = 0 ;
4762
+ long options = 0 ;
4757
4763
char * data , * method , * password , * iv = "" ;
4758
4764
int data_len , method_len , password_len , iv_len = 0 ;
4759
4765
const EVP_CIPHER * cipher_type ;
@@ -4764,7 +4770,7 @@ PHP_FUNCTION(openssl_decrypt)
4764
4770
char * base64_str = NULL ;
4765
4771
zend_bool free_iv ;
4766
4772
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 ) {
4768
4774
return ;
4769
4775
}
4770
4776
@@ -4779,7 +4785,7 @@ PHP_FUNCTION(openssl_decrypt)
4779
4785
RETURN_FALSE ;
4780
4786
}
4781
4787
4782
- if (!raw_input ) {
4788
+ if (!( options & OPENSSL_RAW_DATA ) ) {
4783
4789
base64_str = (char * )php_base64_decode ((unsigned char * )data , data_len , & base64_str_len );
4784
4790
data_len = base64_str_len ;
4785
4791
data = base64_str ;
@@ -4800,6 +4806,9 @@ PHP_FUNCTION(openssl_decrypt)
4800
4806
outbuf = emalloc (outlen + 1 );
4801
4807
4802
4808
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
+ }
4803
4812
EVP_DecryptUpdate (& cipher_ctx , outbuf , & i , (unsigned char * )data , data_len );
4804
4813
outlen = i ;
4805
4814
if (EVP_DecryptFinal (& cipher_ctx , (unsigned char * )outbuf + i , & i )) {
0 commit comments