Bug #74116 [Opn->Nab]: AES-256-GCM not working with uppercase cipher name

From: Date: Fri, 17 Feb 2017 12:52:55 +0000
Subject: Bug #74116 [Opn->Nab]: AES-256-GCM not working with uppercase cipher name
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207430@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74116&edit=1 ID: 74116 Updated by: requinix@php.net Reported by: er dot haridarshan at gmail dot com -Summary: AES-256-GCM not working +Summary: AES-256-GCM not working with uppercase cipher name -Status: Open +Status: Not a bug Type: Bug Package: OpenSSL related Operating System: Fedora 24 PHP Version: 7.1Git-2017-02-17 (snap) Block user comment: N Private report: N New Comment: PHP returns whatever OpenSSL says says without any processing so that would be a question for their project. If you look in their source they have a list of all the ciphers they support https://github.com/openssl/openssl/blob/master/crypto/objects/obj_dat.h and each has two names it can be referenced by: {"AES-256-CBC", "aes-256-cbc", NID_aes_256_cbc, 9, &so[3132]}, {"id-aes256-GCM", "aes-256-gcm", NID_aes_256_gcm, 9, &so[5886]}, The RFC which defined AES-GCM https://tools.ietf.org/html/rfc5084 uses an identifier "id-aes256-GCM" in the spec so I would guess that OpenSSL borrowed that as an official name and created the lowercase "aes-256-gcm" as a nicer alternative. Previous Comments: ------------------------------------------------------------------------ [2017-02-17 12:22:25] er dot haridarshan at gmail dot com Yeah lowercase works. openssl_get_cipher_methods(); returns values algorithm names in capital as well as lower-case but not of aes-256-gcm and few others. Here is the sample output [16] => AES-256-CBC [17] => AES-256-CBC-HMAC-SHA1 [18] => AES-256-CFB [19] => AES-256-CFB1 [20] => AES-256-CFB8 [21] => AES-256-CTR [22] => AES-256-ECB [23] => AES-256-OFB [24] => AES-256-XTS --------------------------------- [101] => aes-256-cbc [102] => aes-256-cbc-hmac-sha1 [103] => aes-256-ccm [104] => aes-256-cfb [105] => aes-256-cfb1 [106] => aes-256-cfb8 [107] => aes-256-ctr [108] => aes-256-ecb [109] => aes-256-gcm [110] => aes-256-ofb [111] => aes-256-xts As you can see aes-256-cbc is returned both in lower-case and upper-case then why not AES-256-GCM ------------------------------------------------------------------------ [2017-02-17 08:28:53] requinix@php.net I assume using a lowercase name works, then? Does openssl_get_cipher_methods() also return the uppercase version? ------------------------------------------------------------------------ [2017-02-17 06:21:10] er dot haridarshan at gmail dot com Sorry didn't noticed algorithm names are case-sensitive. But aren't they supposed to case-insensitive? ------------------------------------------------------------------------ [2017-02-17 06:15:27] er dot haridarshan at gmail dot com Description: ------------ As of 7.1.0, when trying to use AES-256-GCM algorithm with openssl_cipher_iv_length getting warning as PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm And as mentioned in changelog of 7.1.0 OpenSSL: Implemented FR #67304 (Added AEAD support [CCM and GCM modes] to openssl_encrypt and openssl_decrypt). this should work but its not working Test script: --------------- function encrypt($algo = 'AES-256-GCM') { $key = random_bytes(32); // 256 bits $iv = random_bytes(openssl_cipher_iv_length($algo)); $ciphertext = openssl_encrypt( random_bytes(1024 * 1024 * 10), $algo, $key, OPENSSL_RAW_DATA, $iv, $tag ); return $ciphertext; } $cipherText = encrypt(); Expected result: ---------------- Exepected Result is the cipherText Actual result: -------------- PHP Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /var/www/test/aes.php on line 13 Warning: openssl_cipher_iv_length(): Unknown cipher algorithm in /var/www/test/aes.php on line 13 PHP Fatal error: Uncaught Error: Length must be greater than 0 in /var/www/test/aes.php:13 Stack trace: #0 /var/www/test/aes.php(13): random_bytes(false) #1 /var/www/test/aes.php(41): encrypt('Hello') #2 {main} thrown in /var/www/test/aes.php on line 13 Fatal error: Uncaught Error: Length must be greater than 0 in /var/www/test/aes.php:13 Stack trace: #0 /var/www/test/aes.php(13): random_bytes(false) #1 /var/www/test/aes.php(41): encrypt('Hello') #2 {main} thrown in /var/www/test/aes.php on line 13 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74116&edit=1

« previous php.bugs (#207430) next »