Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86395 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45709 invoked from network); 26 May 2015 22:47:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 May 2015 22:47:40 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.41 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.215.41 mail-la0-f41.google.com Received: from [209.85.215.41] ([209.85.215.41:34493] helo=mail-la0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 59/10-43615-A08F4655 for ; Tue, 26 May 2015 18:47:39 -0400 Received: by laat2 with SMTP id t2so77823096laa.1 for ; Tue, 26 May 2015 15:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=E1KHFGSDpJ5/17YVjoFAr0GVQuR8xb8wfvhaFPwd/vE=; b=KENpHDfrurbBndBisevHT74YgPiQqJ9wG+L7UDj2W4yn5MAmRA27eNtm7AeZGxcRhP x55VX7DBEuICOPxJvnfHFfpKUGJUelHHfpe8JFkLOFKWnpI7MvP0HDhfaUx2mPNmdi7R nv9QlUt9x3gVqdZ2DMHlR9AcZYHH1AK/acS1vQyyMMdMwSEZWF5bzl0jr6Mvg6zQnqsS DwzFCK+xaceS9SgHO54ssL7BUyNUiLnbBdKHC4HcpudCEzDJDGPSyHSPudxigrNxNi6z Wv7rsDdbP06yBxg/oawerDUi3/Xh9e50sBC/I4THDzsjbAN60TKtQSJT/wU+VhehOn+y 30Cg== MIME-Version: 1.0 X-Received: by 10.112.16.227 with SMTP id j3mr2452632lbd.43.1432680456045; Tue, 26 May 2015 15:47:36 -0700 (PDT) Received: by 10.25.90.75 with HTTP; Tue, 26 May 2015 15:47:35 -0700 (PDT) In-Reply-To: References: Date: Tue, 26 May 2015 18:47:35 -0400 Message-ID: To: Scott Arciszewski Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] [PHP 7.1] libsodium From: ircmaxell@gmail.com (Anthony Ferrara) Scott, On Wed, May 20, 2015 at 9:15 PM, Scott Arciszewski wrote: > Hi Internals Team, > > I'm sure everyone is really focused (and excited) for PHP 7.0.0 later this > year, and many of you might not want to discuss what 7.1.x looks like yet. > > The current state of cryptography in PHP is, well, abysmal. Our two main > choices for handling symmetric cryptography are libmcrypt (collecting dust > since 2007) and openssl, which lacks a streaming API (e.g. mcrypt_generic) > and GCM support. > > While mcrypt is slowly decomposing in the corner and code is being > desperately migrated towards openssl in case a critical vulnerability is > discovered in the abandonware choice, the libsodium extension has been > growing steadily. Thanks to Remi, it should soon be compatible with both > PHP 5.x and 7.x (decided at compile-time). The libsodium library itself has > landed in Debian 8 and Ubuntu 15.04 and adoption is expected to persist by > the next Ubuntu LTS is released. > > I think now is a good time to talk about the possibility of making > libsodium a core PHP extension, depending on where things are when we near > the 7.1 feature freeze. > > I've just opened an RFC for precisely this purpose: > https://wiki.php.net/rfc/libsodium While I definitely do like libsodium and consider it a step in the right direction, I am hesitant overall. The main reason is precisely what happened with mcrypt. In that a library goes unmaintained, and all of a sudden we're stuck using unsupported crypto. I wonder if a PDO-style approach would be better. Where we can have multiple pluggable backends, and provide backend-specific functionality if needed. Targetting a high-level API, not exposing primitives. Something like: $enc = new SymmetricEncryption(":cipher=aes128;hash=sha256"); // Use any available backend which can do aes128+sha256 mac var_dump($enc->encrypt("plaintext", $key)); $enc = new SymmetricEncryption("openssl:cipher=arc4;mode=ctr"); // Use any available backend which can do aes128+sha256 mac var_dump($enc->encrypt("plaintext", $key)); The concept would be that while parts of the algorithm are controllable by the end-user (like cipher choice, possibly mode, etc), we would attempt to prevent insecure usages (no ECB). If you have a need for custom encryption (web service uses a custom format), then use primitives yourself (like openssl/mcrypt/etc). My one issue with libsodium is that if you need NIST compliance, it does nothing for you (considering it uses XSalsa20+ Poly1305). While this is an advantage for some, it's a disadvantage for many. Ideally, I'd like to see a prototype of this library built in PHP that we can play with prior to making into a PECL extension (and ultimately proposed for core). I'd just rather try to get this right, rather than yet another maybe-good-enough-for-now solution. Anthony