Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93734 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32523 invoked from network); 2 Jun 2016 21:34:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jun 2016 21:34:11 -0000 Authentication-Results: pb1.pair.com header.from=scott@paragonie.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=scott@paragonie.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain paragonie.com designates 209.85.218.50 as permitted sender) X-PHP-List-Original-Sender: scott@paragonie.com X-Host-Fingerprint: 209.85.218.50 mail-oi0-f50.google.com Received: from [209.85.218.50] ([209.85.218.50:35997] helo=mail-oi0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3F/21-24756-256A0575 for ; Thu, 02 Jun 2016 17:34:11 -0400 Received: by mail-oi0-f50.google.com with SMTP id j1so98304151oih.3 for ; Thu, 02 Jun 2016 14:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragonie-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=m2VXGgxQeSsWkd1glXq3QOy7Y81UEI2AIerOPNbobVs=; b=q5zetwXuKzouTNIg/0tuU0ia6pZFrxql8WTTBQBj1KMEUrp+rmw2eZN4L/GlO1tZ5t QfROnz081nrElLdt4Rr/X7E8ACPGMaChHFHH8q3W005VTGaDExJUQt7KD+KYSgqt+AZL i2Hph/NQdEaqpTA4Ide7sNO7pHpS6olaOjAFFpZPBn5tONvsR5Aw2gHNdhH7gDSYwp1m I2cqAzp6uWP14zI5AjYdBOdS/PSADSs1bOqL4S5Q7UlrK2yjsyiKrDWs9NHHF6WYMvgt fHatNHC9hk+NvlzDzjurNmN6CJvUE1J7CnTKWkgSRNpojlciNzj3pjjYImsT2IehSyeA T6PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=m2VXGgxQeSsWkd1glXq3QOy7Y81UEI2AIerOPNbobVs=; b=KydmlJHQw39V+OpLG/Mz3Wo20qZhgLxwjyOPlUu9P0JS7fmjfOiCQBV3hCuuVPy01t d9gfKahrOMKSRgaDjhpO6s99Dg+bySKkYcbq6QmsqGuK9RNgBqJWAknnGrCwHFrm/iUy wYjwYwrPFvdGnPa3vbdCJik3yb+SA2o8PZOtc4pCG5ncjx0lfwzQ7GHBgAGi1KeuXMc9 kTmkofOB3umJHk0xv7m+ho5f3RFVyoZbQO3HGpbF92XmChJlrBwyLhQFoWT77QkZT9oL xp+A7pQnbV1sFW0vLsXx1f1LucRu/lqOwgXaNksupXenW1EAznDXurGxJDbIh87nFRoS kDvA== X-Gm-Message-State: ALyK8tJgDRQKFyz89Npqm/6fFa7Xt2KxAG1wBNLdEpLV5yRNxBD+DCXSeaHkj18gxc1FLAMF5+yFFeY1lqhnbA== MIME-Version: 1.0 X-Received: by 10.202.186.193 with SMTP id k184mr194827oif.66.1464903247218; Thu, 02 Jun 2016 14:34:07 -0700 (PDT) Received: by 10.157.26.106 with HTTP; Thu, 2 Jun 2016 14:34:07 -0700 (PDT) In-Reply-To: References: <295c09d5-01af-1528-8e61-00dc6ee6c69e@fleshgrinder.com> <52b8417d-4d23-338c-0737-562ddc7476b5@fleshgrinder.com> Date: Thu, 2 Jun 2016 17:34:07 -0400 Message-ID: To: Niklas Keller Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a113ce218ae6a5d0534525d81 Subject: Re: [PHP-DEV] [RFC] Libsodium - Discussion From: scott@paragonie.com (Scott Arciszewski) --001a113ce218ae6a5d0534525d81 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, Jun 2, 2016 at 2:10 PM, Niklas Keller wrote: > 2016-06-02 19:36 GMT+02:00 Fleshgrinder : > >> On 6/1/2016 9:25 PM, Niklas Keller wrote: >> > Why does it directly extend throwable? >> > >> > Just a short node: the keys shouldn't be responsible for signing / >> > verification. >> > >> >> This was not a real proposal, I only wanted to illustrate the potential >> for a nice OO implementation. >> > > Yes, sure. > > >> The goal is it to make crypto simpler for userland. Well, having >> dedicated classes and everything type hinting against those makes it >> very easy. >> >> For instance nonce arguments ... >> >> $nonce =3D randombytes_buf(CRYPTO_SECRETBOX_NONCEBYTES); >> crypto_secretbox(... >> >> $message_nonce =3D randombytes_buf(CRYPTO_BOX_NONCEBYTES); >> crypto_box(... >> >> $nonce =3D randombytes_buf(CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES); >> crypto_aead_chacha20poly1305_encrypt(... >> >> $nonce =3D randombytes_buf(CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES= ); >> crypto_aead_chacha20poly1305_ietf_encrypt(... >> >> $nonce =3D randombytes_buf(CRYPTO_AEAD_AES256GCM_NPUBBYTES); >> crypto_aead_aes256gcm_encrypt(... >> >> ... >> >> This is not only super annoying, it also requires you to perform the >> same fixtures all the time and allows users to make mistakes, e.g. >> reusing the same nonce. >> > > I agree, we should expose a higher level API. For nonces, a random value > might even be bad, because of the birthday paradoxon. But it's probably > best if the user doesn't even have to care about generating a nonce > manually. > > >> namespace Php\Sodium { >> >> class Nonce { >> >> function __construct(int $bytes); >> >> function __toString(): string; >> >> function getBytes(): int; >> >> } >> >> } >> >> namespace Php\Sodium\Asymmetric { >> >> class EncryptedMessage { >> >> function decrypt(PrivateKey $private_key): Message; >> >> function getNonce(): Nonce; >> >> } >> >> class Message { >> >> function __construct(string $plain_text); >> >> function encrypt(PublicKey $public_key): EncryptedMessage; >> >> } >> >> } >> >> Of course some of the provided stuff is not well suited for OO but those >> could be implemented normally as procedural functions. However, I >> question the names and the functionality of some. For instance: >> >> Isn't randombytes_buf() pretty much the same as random_bytes()? >> > > Yes, and thus I think it shouldn't be exposed to userland. > > >> randombytes_uniform() has a weird name that does not really tell what it >> does. random_int_uniform() would be better and match the existing >> random_int() function. >> >> Why does randombytes_random16() even exist? It does exactly the same as >> randombytes_uniform(65536)? >> >> Again, I really like the goal but I don't think that the current >> proposal meets it. I also understand the desire to have it in 7.1 but it >> is the same problem as in every company: rushing is bad! Once released >> we're done. We cannot remove it anymore, we cannot change it anymore, we >> have to live with it. All because we wanted something better but too fas= t. >> >> Let's give it some time to come up with a simpler solution that >> integrates nicely into existing PHP. Without confusion over functions >> that are doing what already existing functions to. With classes that >> encapsulate complicated stuff and make it hard to get things wrong. >> >> -- >> Richard "Fleshgrinder" Fussenegger >> >> > =E2=80=8BThe birthday bound of a crypto_box or crypto_secretbox nonce, gene= rated from a CSPRNG, is 2^96 for one collision. If it's gonna happen, you've got bigger things to worry about. I should probably state clearly that the concept of an abstract pluggable crypto API that supports OpenSSL and Libsodium isn't what I'm proposing here. Just libsodium.=E2=80=8B If I find time to write the pluggable crypto API, I will propose that next. Unfortunately, that likely won't be until 7.2. Scott Arciszewski Chief Development Officer Paragon Initiative Enterprises =E2=80=8B --001a113ce218ae6a5d0534525d81--