Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93685 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84441 invoked from network); 1 Jun 2016 17:53:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jun 2016 17:53:17 -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.43 as permitted sender) X-PHP-List-Original-Sender: scott@paragonie.com X-Host-Fingerprint: 209.85.218.43 mail-oi0-f43.google.com Received: from [209.85.218.43] ([209.85.218.43:34433] helo=mail-oi0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3F/93-63812-C012F475 for ; Wed, 01 Jun 2016 13:53:17 -0400 Received: by mail-oi0-f43.google.com with SMTP id e72so39690857oib.1 for ; Wed, 01 Jun 2016 10:53:16 -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=Fvrt9p4yHgl/sxcrFFS1hkSMLncqSLXbIp+LGm8198w=; b=EQ1UC/NMeVpAXCrH1tbPzjVYJk5dk9QkpQxXCwI2fdqQxbi7Om2HNNTq5cCMZf21QO NDp65sNhHim2n8z9dFse2A1XzDoGYqAITjxj+EFBUfrLZErlOpcXn0iyJinj9SeIQPYa RGC+Er65isfcoU4UtokTyk0SpyoBJ+lkqaYAsQ3IcLa2S07fCquGIBpTLuFw6GekdiON 0rfc5NgJuxDxclUkOpvEgOzYG0lIFN/wSr1h0FAk73kbrodzxrUif2FyzGey6yGPm0EW W7ngPtOj17RRqxQIvH20jFmvn0RJUhbE3xAK3bqsynCVMIhwlX5VcyRrpbKRq/ZOpy1X ZghA== 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=Fvrt9p4yHgl/sxcrFFS1hkSMLncqSLXbIp+LGm8198w=; b=Et9/lTIh4H/xaJWRH7+O8y8QJL4WNp5wTnKBBPPFAfCfuzUnDD0cBajaUXvRv+a1SN 4ImMiQ097wbNbcqWDAa1aFmZrJZhxENKcw1Fx3U2RSIyjWnm/thnDcf/9/eL4k7kL4AG QUvIqcyr0xu1qzn2B82vPLL4dk5SeaIL6eTzZ7BjqHdsDUvmI1k+/FkxaMA2mGo6ePwq FoBWPMCiE3KCwjfZx4FsJ2oNc9CR8Rp/aAC8Jhhyr4PnaGjzrEe3oJy8IEsvwm/GbOv/ iNqiq1sYez2rRseVrUfAwPqigBP12sbjHE542FyT2IdcKt/DXMJnaE07gdpd4iBFwxmt GS0w== X-Gm-Message-State: ALyK8tL0UeVMIB+MwRlm0TaPQoZ19CmIMwq3+NQueOt8elj8FNqkfAXj+c7VOQ7U7VAL8dUUdawY4JT7wZ06rw== MIME-Version: 1.0 X-Received: by 10.202.51.133 with SMTP id z127mr21695938oiz.202.1464803593916; Wed, 01 Jun 2016 10:53:13 -0700 (PDT) Received: by 10.157.26.106 with HTTP; Wed, 1 Jun 2016 10:53:13 -0700 (PDT) In-Reply-To: <295c09d5-01af-1528-8e61-00dc6ee6c69e@fleshgrinder.com> References: <295c09d5-01af-1528-8e61-00dc6ee6c69e@fleshgrinder.com> Date: Wed, 1 Jun 2016 13:53:13 -0400 Message-ID: To: PHP Internals Cc: Marco Pivetta Content-Type: multipart/alternative; boundary=001a113cddece1abd505343b29a1 Subject: Re: [PHP-DEV] [RFC] Libsodium - Discussion From: scott@paragonie.com (Scott Arciszewski) --001a113cddece1abd505343b29a1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Jun 1, 2016 at 1:26 PM, Fleshgrinder wrote: > On 6/1/2016 12:48 PM, Marco Pivetta wrote: > > > I also agree with Remi on naming: let's avoid calling the extension > > `libsodium`. > > > > I agree here too. > > On 6/1/2016 12:48 PM, Marco Pivetta wrote: > > 1. is there a particular reason why abbreviations are used? For > instance, > > why `sodium_randombytes_buf()` instead of `sodium_random_bytes_buffer()= `? > > 2. from a naming perspective, I'd expect `sodium_randombytes_buf()` to > > give me a buffer of random bytes (probably as a stream), but it returns > the > > actual string of random bytes. Again: confusing naming > > 3. can we avoid using "themed" naming? For example, instead of > > `sodium_crypto_secretbox()`, it would be best to express what it actual= ly > > does, like `sodium_encrypt_and_sign()`. While the naming may be emergin= g > > from lower layers, I still (like I did with other RFCs) disagree with > > inheriting confusing naming. This will just cause users to look up the > > naming up when reading or writing code, and ultimately add up to silly > > bugs. I can already foresee that people will use the API incorrectly ju= st > > because of the naming. > > > > I agree here too but read on. > > On 6/1/2016 12:48 PM, Marco Pivetta wrote: > > 4. can't we just keep it namespaced under `Sodium`, instead of adding > more > > stuff to the root level namespace? Does anyone have a reference to the > > coding standards that would cause the rename? > > > > I was the person who brought this up because it is not desired according > to the existing CODING STANDARD: > > https://github.com/php/php-src/blob/master/CODING_STANDARDS > > Note that it also encourages this weird C style naming with > abbreviations, hence, I would be open for discussing it. That being > said, I am not a friend of putting procedural functions into namespaces > and prefer the establish prefix approach. > > That being said, I see many opportunities here to create very nice > classes that enable dependency injection, single validation, and of > course I am +1000 for namespaces here. It would also help a lot to get > some of those extremely weird names out of the window. > > namespace Sodium; > > interface SodiumException extends \Throwable {} > > class SignatureException > extends \UnexpectedValueException > implements SodiumException {} > > class DetachedSignature { > > public function __construct(string $detached_signature); > > public function __toString(): string; > > public function verify(string $message, PublicKey $public): bool; > > } > > class SignedMessage { > > public function __construct(string $signed_message); > > public function __toString(): string; > > public function getSignature(): DetachedSignature; > > } > > interface Key { > > } > > class PrivateKey implements Key { > > public function sign(string $message): SignedMessage; > > } > > class PublicKey implements Key { > > public function verify(SignedMessage $message): bool; > > } > > class KeyPair { > > public function __construct(PrivateKey $private, PublicKey $public); > > public static function generate(): KeyPair; > > public function getPrivate(): PrivateKey; > > public function getPublic(): PublicKey; > > } > > This is of course an attempt of writing up some classes after looking at > the API for literally 5 minutes but I think it illustrated the > potential. It is also going to increase the security by a huge margin > because a private key suddenly has to be an instance of a PrivateKey and > not some arbitrary string that needs to be revalidated all the time. > > The same software design principles apply as always and the current API > might be nice for C but it is definitely not for PHP in my opinion. > > Of course I offer my help to find and define such an API if you guys are > interested in creating one. :) > > -- > Richard "Fleshgrinder" Fussenegger > > =E2=80=8BWell, for what it's worth, I did write https://github.com/paragoni= e/halite =E2=80=8B as a high-level abstraction. The goal of this RFC is to get the lower-level functionality (which is still, I promise, a high-level cryptography API) available.=E2=80=8B Scott Arciszewski Chief Development Officer Paragon Initiative Enterprises =E2=80=8B --001a113cddece1abd505343b29a1--