Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93727 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11585 invoked from network); 2 Jun 2016 18:10:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jun 2016 18:10:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.220 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.220 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.220] ([81.169.146.220:63177] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 77/E7-62101-A9670575 for ; Thu, 02 Jun 2016 14:10:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1464891031; l=8500; s=domk; d=kelunik.com; h=Content-Type:Cc:To:From:Subject:Date:References:In-Reply-To: MIME-Version; bh=IqKILLs36J1sL4WRwTTGcVSx7glG4A6v59skcH3JBkU=; b=jLBX+orAM1IQ/JaGyBor9LZkKK1TBPZ2Vx4ZwPty7MgMkE1uii+pwby+GibW6qvo0FD 8fEAXZ2UUD2Snz1d1+SMc/uS20NIernONXEqpxnuw6QGjA4Vc5L1JsVuQuFbACzRs7QaO ZjxwRnYv+FYgg703ptXiz3K9LdKqaPjL3Rg= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtO3U6 X-RZG-CLASS-ID: mo00 Received: from mail-wm0-f46.google.com ([74.125.82.46]) by smtp.strato.de (RZmta 38.1 AUTH) with ESMTPSA id j07781s52IAVB4J (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp384r1 with 384 ECDH bits, eq. 7680 bits RSA)) (Client did not present a certificate) for ; Thu, 2 Jun 2016 20:10:31 +0200 (CEST) Received: by mail-wm0-f46.google.com with SMTP id z87so79730708wmh.0 for ; Thu, 02 Jun 2016 11:10:31 -0700 (PDT) X-Gm-Message-State: ALyK8tKclDAlLKokcrCz0i+Nk0H/dVLUTcJ67SFcawbvgq1kK+rKBDtTZ/YHcEhANdh0UBLy4+cXqBZh3BYHdQ== MIME-Version: 1.0 X-Received: by 10.194.11.97 with SMTP id p1mr9718336wjb.159.1464891031041; Thu, 02 Jun 2016 11:10:31 -0700 (PDT) Received: by 10.28.53.132 with HTTP; Thu, 2 Jun 2016 11:10:30 -0700 (PDT) In-Reply-To: <52b8417d-4d23-338c-0737-562ddc7476b5@fleshgrinder.com> References: <295c09d5-01af-1528-8e61-00dc6ee6c69e@fleshgrinder.com> <52b8417d-4d23-338c-0737-562ddc7476b5@fleshgrinder.com> Date: Thu, 2 Jun 2016 20:10:30 +0200 X-Gmail-Original-Message-ID: Message-ID: To: PHP Internals Cc: Scott Arciszewski Content-Type: multipart/alternative; boundary=047d7b4508e48a4ae005344f85de Subject: Re: [PHP-DEV] [RFC] Libsodium - Discussion From: me@kelunik.com (Niklas Keller) --047d7b4508e48a4ae005344f85de Content-Type: text/plain; charset=UTF-8 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 = randombytes_buf(CRYPTO_SECRETBOX_NONCEBYTES); > crypto_secretbox(... > > $message_nonce = randombytes_buf(CRYPTO_BOX_NONCEBYTES); > crypto_box(... > > $nonce = randombytes_buf(CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES); > crypto_aead_chacha20poly1305_encrypt(... > > $nonce = randombytes_buf(CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES); > crypto_aead_chacha20poly1305_ietf_encrypt(... > > $nonce = 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 fast. > > 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 > > --047d7b4508e48a4ae005344f85de--