Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81534 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7806 invoked from network); 1 Feb 2015 17:49:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Feb 2015 17:49:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=rdlowrey@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rdlowrey@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.181 as permitted sender) X-PHP-List-Original-Sender: rdlowrey@gmail.com X-Host-Fingerprint: 209.85.213.181 mail-ig0-f181.google.com Received: from [209.85.213.181] ([209.85.213.181:57050] helo=mail-ig0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9C/21-33325-1276EC45 for ; Sun, 01 Feb 2015 12:49:22 -0500 Received: by mail-ig0-f181.google.com with SMTP id hn18so12487362igb.2 for ; Sun, 01 Feb 2015 09:49:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=7gFczKm0k7ctshn3PnqydIEtXCVKhbVw0KiJh3whPFw=; b=hfs4BSbux5Wji0InOKrKMlVT0O/NaSq6WY8y+i7onmjzs2ItSuOc/gfZzC2DD/mi1o v98lDT7bf6bxiYaAzCo5CL0OwJWWlGHaqkR6SOmX1q9/t9Br3koXiRMxUNotBxWVQeTa OuapNgCqUkbyZ670amk4oYh62Voo6QHY2J+veT8hgPWsUW5KfWW7+neEd6gAw5WM7qnO GpZRcAP5PWCRtJnE2ZjOxGN4+2k6FODu1U4MqV61xOukUHtSBLZB2AREiPPttvOVQ+1d vxZVsXcZELLU3bg9W1JDxhvppWpar9lpx2Icl3IAfp7noaOybV+SyUagEoE/uw2/RB/+ SvPQ== MIME-Version: 1.0 X-Received: by 10.50.253.12 with SMTP id zw12mr7638076igc.24.1422812959251; Sun, 01 Feb 2015 09:49:19 -0800 (PST) Sender: rdlowrey@gmail.com Received: by 10.50.156.198 with HTTP; Sun, 1 Feb 2015 09:49:19 -0800 (PST) Date: Sun, 1 Feb 2015 12:49:19 -0500 X-Google-Sender-Auth: OeHv4iF5R-VyhXcpZpwHfk48DNg Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11346e3c04a3ec050e0a7575 Subject: Re: OpenSSL ext. improvements for authenticated cipher modes. From: rdlowrey@php.net (Daniel Lowrey) --001a11346e3c04a3ec050e0a7575 Content-Type: text/plain; charset=UTF-8 > Hi list, > > A couple of bug reports have highlighted the fact that our > openssl_encrypt and openssl_decrupt functions have no way of getting > or setting tags required for authenticated cipher modes (i.e. GCM, > CCM, OCB (not sure if this is available in OpenSSL)). > > https://bugs.php.net/bug.php?id=68962 > https://bugs.php.net/bug.php?id=67304 > > Further to this, we have no way of setting any associated data. > > I think we absolutely must provide a method for users to be able to > use authenticated encryption, and would like some opinions on how much > flexibility we give users, and the best method for exposing this > functionality. > > At the very basic end of the spectrum, we could have openssl_get_tag > and openssl_set_tag, or add an extra parameter to the end of > openssl_encrypt and openssl_decrypt (pass by ref for encrypt, like > preg $matches) this would cover the majority of use cases. > > However I absolutely think that the associated data also needs to be > supported, and possibly the ability to change the tag length. > > At this point we're starting to get into the territory where an > $options array is needed, or we add a lot of parameters to the end of > functions. I don't really think it's good to add up to 3 more params > to these functions. > > What do you guys and girls think is the best way of tackling this? How about ... Old API: -------- string openssl_decrypt ( string $data , string $method , string $password [, int $options = 0 [, string $iv = "" ]] ) string openssl_encrypt ( string $data , string $method , string $password [, int $options = 0 [, string $iv = "" ]] ) New: -------- mixed openssl_decrypt ( string $data , string $method , string $password [, mixed $options = 0 [, string $iv = "" ]] ) string openssl_encrypt ( string $data , string $method , string $password [, mixed $options = 0 [, string $iv = "" ]] ) The main changes are: - the $options parameter becomes mixed (either long or array) in both functions - a long $options parameter triggers E_DEPRECATED in php7 (expects array) - the presence of an $iv triggers E_DEPRECATED in php7 (scheduled for removal) - openssl_decrypt() now returns mixed ... if $options['get_tag'] == true then return [$decryptedString, $tag], otherwise return $decrypted string as before to preserve BC. - the encrypt function could use $options['set_tag'] to define that (or any other secondary information needed for the operation). This has zero BC implications, emits deprecation warnings for the old way of doing it and finally provides a schedule for eventual removal of the excessively verbose API in PHP8. What I would prefer NOT to see is piling on more optional parameters to these already too-long function signatures. Also, I don't really like the idea of adding "state" to this operation with new openssl_set_tag/openssl_get_tag functions. Thoughts? --001a11346e3c04a3ec050e0a7575--