Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118271 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 45034 invoked from network); 16 Jul 2022 19:38:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Jul 2022 19:38:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0BE83180339 for ; Sat, 16 Jul 2022 14:33:47 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 16 Jul 2022 14:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1658007224; bh=6KEFGQ5lMtKTj5Ut6g9HaUF9hTPdM5fqvbIy1eLe8eg=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Jv/IlhJedDcL0264dSFAKsz8xNzYQ8PV8sBZwoHBvoxFSyGguGL4gH8iCjFACILGq zWC+8kF8C9TPAvcDP6Lobv4P3/YjfqQbANGKLN5uZYFihbG8MbOrGN/dgySPeDK0j3 tZHpGtWtQcwFCHid2U++ipt9MwtL+HIqt7Coo4rS9SuqXF0wLDGmF5ZjNLFtg58rKb TF2/RvOC0YXa3yZwy5vmZQOfkvwwH8Pg/Ep8WURxnfyWOv9levqXljUBpG7+lbB5hN KO/CmdCkiqAuvAy/3A0o+FtzR6vZH8C9m7sf85fPoubbdCM3soUZTux74CqnqvMccl YTlm2AQtqrHKQ== Message-ID: Date: Sat, 16 Jul 2022 23:33:42 +0200 MIME-Version: 1.0 Content-Language: en-US To: Go Kudo , PHP internals References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] What do you think CSPRNG in PHP From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 7/15/22 17:54, Go Kudo wrote: > However, there are several challenges to this. > > - Increased maintenance costs > - Requires optimization for CPU architecture > - Requires familiarity with CSPRNG > > PHP already bundles xxHash and appears ready to make this happen. > > Also, an appropriate CSPRNG implementation may be able to resolve the > current complex macro branching. > > What do you think about this? This would be a strong no from my side. There's all types of failure modes that decrease the security of the CSPRNG (i.e. making it insecure) and we really don't want to be the ones to blame if something goes wrong. And historically many non-kernel CSPRNGs later proved to be insecure in specific situations. I also would assume that for a typical PHP application both of the following is true: - The majority of the requests don't need any randomness. - The majority of the requests that *need* randomness don't need any significant amount of randomness. - The majority of the requests that need significant amounts of randomness are fine with a regular PRNG (e.g. Xoshiro or Pcg). - The cost of a few getrandom() syscalls is not really measurable compared to the time spent waiting for the database, file IO or template rendering. Attempting to optimize the speed of the CSPRNG is premature optimization. That also the reason why I suggested to use the 'Secure' engine by default in the Randomizer: It's a safe default choice for the vast majority of users. Personally I likely wouldn't have merged the PR in question for the same reasons. But at least in that case glibc is at fault :-) Best regards Tim Düsterhus