@@ -7590,44 +7590,76 @@ PHP_FUNCTION(openssl_decrypt)
75907590}
75917591/* }}} */
75927592
7593- PHP_OPENSSL_API zend_long php_openssl_cipher_iv_length (const char * method )
7593+ static inline const EVP_CIPHER * php_openssl_get_evp_cipher_by_name (const char * method )
75947594{
75957595 const EVP_CIPHER * cipher_type ;
75967596
75977597 cipher_type = EVP_get_cipherbyname (method );
75987598 if (!cipher_type ) {
75997599 php_error_docref (NULL , E_WARNING , "Unknown cipher algorithm" );
7600- return -1 ;
7600+ return NULL ;
76017601 }
76027602
7603- return EVP_CIPHER_iv_length (cipher_type );
7603+ return cipher_type ;
7604+ }
7605+
7606+ PHP_OPENSSL_API zend_long php_openssl_cipher_iv_length (const char * method )
7607+ {
7608+ const EVP_CIPHER * cipher_type = php_openssl_get_evp_cipher_by_name (method );
7609+
7610+ return cipher_type == NULL ? -1 : EVP_CIPHER_iv_length (cipher_type );
76047611}
76057612
7606- /* {{{ */
76077613PHP_FUNCTION (openssl_cipher_iv_length )
76087614{
7609- char * method ;
7610- size_t method_len ;
7615+ zend_string * method ;
76117616 zend_long ret ;
76127617
7613- if (zend_parse_parameters (ZEND_NUM_ARGS (), "s " , & method , & method_len ) == FAILURE ) {
7618+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "S " , & method ) == FAILURE ) {
76147619 RETURN_THROWS ();
76157620 }
76167621
7617- if (! method_len ) {
7622+ if (ZSTR_LEN ( method ) == 0 ) {
76187623 zend_argument_value_error (1 , "cannot be empty" );
76197624 RETURN_THROWS ();
76207625 }
76217626
76227627 /* Warning is emitted in php_openssl_cipher_iv_length */
7623- if ((ret = php_openssl_cipher_iv_length (method )) == -1 ) {
7628+ if ((ret = php_openssl_cipher_iv_length (ZSTR_VAL ( method ) )) == -1 ) {
76247629 RETURN_FALSE ;
76257630 }
76267631
76277632 RETURN_LONG (ret );
76287633}
7629- /* }}} */
76307634
7635+ PHP_OPENSSL_API zend_long php_openssl_cipher_key_length (const char * method )
7636+ {
7637+ const EVP_CIPHER * cipher_type = php_openssl_get_evp_cipher_by_name (method );
7638+
7639+ return cipher_type == NULL ? -1 : EVP_CIPHER_key_length (cipher_type );
7640+ }
7641+
7642+ PHP_FUNCTION (openssl_cipher_key_length )
7643+ {
7644+ zend_string * method ;
7645+ zend_long ret ;
7646+
7647+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "S" , & method ) == FAILURE ) {
7648+ RETURN_THROWS ();
7649+ }
7650+
7651+ if (ZSTR_LEN (method ) == 0 ) {
7652+ zend_argument_value_error (1 , "cannot be empty" );
7653+ RETURN_THROWS ();
7654+ }
7655+
7656+ /* Warning is emitted in php_openssl_cipher_key_length */
7657+ if ((ret = php_openssl_cipher_key_length (ZSTR_VAL (method ))) == -1 ) {
7658+ RETURN_FALSE ;
7659+ }
7660+
7661+ RETURN_LONG (ret );
7662+ }
76317663
76327664PHP_OPENSSL_API zend_string * php_openssl_random_pseudo_bytes (zend_long buffer_length )
76337665{
0 commit comments