php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #66650
Patch add-CTR-mode revision 2014-02-05 21:37 UTC by clicky at erebot dot net

Patch add-CTR-mode for mcrypt related Bug #66650

Patch version 2014-02-05 21:37 UTC

Return to Bug #66650 | Download this patch
Patch Revisions:

Developer: clicky@erebot.net

--- a/ext/mcrypt/mcrypt.c	2014-02-05 00:06:04.000000000 +0100
+++ b/ext/mcrypt/mcrypt.c	2014-02-05 00:07:30.000000000 +0100
@@ -226,27 +226,36 @@
 ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_ofb, 0, 0, 5)
 	ZEND_ARG_INFO(0, cipher)
 	ZEND_ARG_INFO(0, key)
 	ZEND_ARG_INFO(0, data)
 	ZEND_ARG_INFO(0, mode)
 	ZEND_ARG_INFO(0, iv)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_ctr, 0, 0, 5)
+	ZEND_ARG_INFO(0, cipher)
+	ZEND_ARG_INFO(0, key)
+	ZEND_ARG_INFO(0, data)
+	ZEND_ARG_INFO(0, mode)
+	ZEND_ARG_INFO(0, iv)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_create_iv, 0, 0, 2)
 	ZEND_ARG_INFO(0, size)
 	ZEND_ARG_INFO(0, source)
 ZEND_END_ARG_INFO()
 /* }}} */
 
 const zend_function_entry mcrypt_functions[] = { /* {{{ */
 	PHP_DEP_FE(mcrypt_ecb, 				arginfo_mcrypt_ecb)
 	PHP_DEP_FE(mcrypt_cbc, 				arginfo_mcrypt_cbc)
 	PHP_DEP_FE(mcrypt_cfb, 				arginfo_mcrypt_cfb)
 	PHP_DEP_FE(mcrypt_ofb, 				arginfo_mcrypt_ofb)
+	PHP_DEP_FE(mcrypt_ctr, 				arginfo_mcrypt_ctr)
 	PHP_FE(mcrypt_get_key_size, 	arginfo_mcrypt_get_key_size)
 	PHP_FE(mcrypt_get_block_size, 	arginfo_mcrypt_get_block_size)
 	PHP_FE(mcrypt_get_cipher_name, 	arginfo_mcrypt_get_cipher_name)
 	PHP_FE(mcrypt_create_iv, 		arginfo_mcrypt_create_iv)
 
 	PHP_FE(mcrypt_list_algorithms, 	arginfo_mcrypt_list_algorithms)
 	PHP_FE(mcrypt_list_modes, 		arginfo_mcrypt_list_modes)
 	PHP_FE(mcrypt_get_iv_size, 		arginfo_mcrypt_get_iv_size)
@@ -462,16 +471,17 @@
 	MCRYPT_ENTRY2_2_4(RC6, "rc6");
 	MCRYPT_ENTRY2_2_4(SKIPJACK, "skipjack");
 /* modes */
 	MCRYPT_ENTRY2_2_4(MODE_CBC, "cbc");
 	MCRYPT_ENTRY2_2_4(MODE_CFB, "cfb");
 	MCRYPT_ENTRY2_2_4(MODE_ECB, "ecb");
 	MCRYPT_ENTRY2_2_4(MODE_NOFB, "nofb");
 	MCRYPT_ENTRY2_2_4(MODE_OFB, "ofb");
+	MCRYPT_ENTRY2_2_4(MODE_CTR, "ctr");
 	MCRYPT_ENTRY2_2_4(MODE_STREAM, "stream");
 	REGISTER_INI_ENTRIES();
 
 	php_stream_filter_register_factory("mcrypt.*", &php_mcrypt_filter_factory TSRMLS_CC);
 	php_stream_filter_register_factory("mdecrypt.*", &php_mcrypt_filter_factory TSRMLS_CC);
 
 	return SUCCESS;
 }
@@ -1363,16 +1373,32 @@
 	MCRYPT_GET_CRYPT_ARGS
 
 	convert_to_long_ex(mode);
 
 	php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, "ofb", iv, iv_len, ZEND_NUM_ARGS(), Z_LVAL_PP(mode), return_value TSRMLS_CC);
 }
 /* }}} */
 
+/* {{{ proto string mcrypt_ctr(int cipher, string key, string data, int mode, string iv)
+   CTR crypt/decrypt data using key key with cipher cipher starting with iv as counter */
+PHP_FUNCTION(mcrypt_ctr)
+{
+	zval **mode;
+	char *cipher, *key, *data, *iv = NULL;
+	int cipher_len, key_len, data_len, iv_len = 0;
+	
+	MCRYPT_GET_CRYPT_ARGS
+
+	convert_to_long_ex(mode);
+
+	php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, "ctr", iv, iv_len, ZEND_NUM_ARGS(), Z_LVAL_PP(mode), return_value TSRMLS_CC);
+}
+/* }}} */
+
 /* {{{ proto string mcrypt_create_iv(int size, int source)
    Create an initialization vector (IV) */
 PHP_FUNCTION(mcrypt_create_iv)
 {
 	char *iv;
 	long source = RANDOM;
 	long size;
 	int n = 0;
--- a/ext/mcrypt/php_mcrypt.h	2014-02-04 23:17:49.000000000 +0100
+++ b/ext/mcrypt/php_mcrypt.h	2014-02-04 23:17:29.000000000 +0100
@@ -30,16 +30,17 @@
 extern zend_module_entry mcrypt_module_entry;
 #define mcrypt_module_ptr &mcrypt_module_entry
 
 /* Functions for both old and new API */
 PHP_FUNCTION(mcrypt_ecb);
 PHP_FUNCTION(mcrypt_cbc);
 PHP_FUNCTION(mcrypt_cfb);
 PHP_FUNCTION(mcrypt_ofb);
+PHP_FUNCTION(mcrypt_ctr);
 PHP_FUNCTION(mcrypt_get_cipher_name);
 PHP_FUNCTION(mcrypt_get_block_size);
 PHP_FUNCTION(mcrypt_get_key_size);
 PHP_FUNCTION(mcrypt_create_iv);
 
 /* Support functions for old API */
 PHP_FUNCTION(mcrypt_list_algorithms);
 PHP_FUNCTION(mcrypt_list_modes);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 03:01:28 2024 UTC