php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66650 Support for CTR mode
Submitted: 2014-02-05 21:36 UTC Modified: 2016-08-03 16:31 UTC
From: clicky at erebot dot net Assigned: cmb (profile)
Status: Wont fix Package: mcrypt related
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-02-05 21:36 UTC] clicky at erebot dot net
Description:
------------
Please add support for the CTR encryption mode (MCRYPT_MODE_CTR).

See also attached patch against PHP 5.5.x which adds the necessary code and also defines a deprecated function mcrypt_ctr() (for consistency with other modes).

Test script:
---------------
<?php

$key      = "FooBar";
$secret   = "PHP Testfest 2008";
$cipher   = MCRYPT_RIJNDAEL_128;
$iv       = mcrypt_create_iv(mcrypt_get_iv_size($cipher, MCRYPT_MODE_CTR), MCRYPT_RAND);
$enc_data = mcrypt_ctr($cipher, $key, $secret, MCRYPT_ENCRYPT, $iv);
var_dump(bin2hex($enc_data));

?>

Expected result:
----------------
string(34) "5e42855e8236dacdb8fafbdaa12d176f13"

Actual result:
--------------
Bunch of errors due to lack of MCRYPT_MODE_CTR constant and undefined function mcrypt_ctr().

Patches

add-CTR-mode (last revision 2014-02-05 21:37 UTC by clicky at erebot dot net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-06 11:55 UTC] narf at devilix dot net
You can use ctr mode by just passing 'ctr' to mcrypt_encrypt(). All of the MCRYPT_MODE_* constants just define strings and are not actually necessary. In fact they don't help you with anything.

MCRYPT_MODE_CBC = 'cbc'
MCRYPT_MODE_ECB = 'ecb'
etc.

I'd rather suggest to deprecate usage of the MCRYPT_MODE_* constants.
 [2016-08-03 16:31 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2016-08-03 16:31 UTC] cmb@php.net
> I'd rather suggest to deprecate usage of the MCRYPT_MODE_*
> constants.

Actually, the complete mcrypt extension is deprecated as of PHP
7.1.0, so it doesn't make sense to add new features to it.
 [2016-08-03 16:31 UTC] cmb@php.net
-Status: Closed +Status: Wont fix
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Aug 12 03:01:27 2020 UTC