Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91875 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73823 invoked from network); 22 Mar 2016 23:40:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Mar 2016 23:40:14 -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.214.178 as permitted sender) X-PHP-List-Original-Sender: scott@paragonie.com X-Host-Fingerprint: 209.85.214.178 mail-ob0-f178.google.com Received: from [209.85.214.178] ([209.85.214.178:32963] helo=mail-ob0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/B7-30596-BD7D1F65 for ; Tue, 22 Mar 2016 18:40:12 -0500 Received: by mail-ob0-f178.google.com with SMTP id xj3so43769995obb.0 for ; Tue, 22 Mar 2016 16:40: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=sKpCjw+ZgH+rr3EgJnMIkbYXiMbS4D0YeLXfVg5wgnE=; b=jGfBhdeTgz6cu98ORcDxMsXR/ZtrPqSLMzbjm6hXYfeaevmX8obBb32onw6RI8cuVE SZwhMQd5AR4sBoGIerHBRGyYF9bIsZL9suzfQo7u3hIhmZVhwCYks0vSMXQY3yG3ehmQ Vy+XxKHVrhfID7FSNM41oH4Ny9VdzIt7GqJYObi5CKmn9VKoFi6TSToN897+G6cxEIWt S4v3uMil5lQHi7VUmUCk1CbUzdQ3q2+4yRvKQ9PF03FfrBPwvKpMA1cY6Yj0/3IUlUBB tTtY14Hn7fq/Z+Aq1bBMNbQVgVw9zuGHh3lVtreK/I7v4ebtLCdVJZ8oENUipYHLzcpY qV6w== 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=sKpCjw+ZgH+rr3EgJnMIkbYXiMbS4D0YeLXfVg5wgnE=; b=HNW3BZM/0aJq47rl4MR17W4IjVfiePqsejcKpDP/TSZJG5KCZsO/HukhlXoEPxxzuE Ftdm6pwTF7/Up/lhvzDKWB0N8gUfqHlML66rj0CpJGJJQMf+E0ydkJJWuTfVlcewv3qm aMT0XhLKYLfKgez4CFKcKdMFEievA0kfQOLUUANLr1rVTj0hZyYZuspdfPYCeOGhOhkI weK5f3wdDbkIl0Y54qjALoSwgB50BdZuD0IvcEUGIw9UN71bKFbCLiWxuiR/zcDFhtNM N63iJG39F2Ssn4v0u5hzXZTCTNvz5zApHqMNIOYvU41EdN+0fiHW/RtexijczT6v7bg2 XIKw== X-Gm-Message-State: AD7BkJKdSXQJaOZ42jooqrSMh3cgAt/p/k8THA1+aWe+ev1RpX+9vewl+hbeQDdg3CftwBAhjdJ63l2qk8a1XA== MIME-Version: 1.0 X-Received: by 10.60.227.5 with SMTP id rw5mr21706874oec.54.1458690007533; Tue, 22 Mar 2016 16:40:07 -0700 (PDT) Received: by 10.157.14.47 with HTTP; Tue, 22 Mar 2016 16:40:07 -0700 (PDT) In-Reply-To: <91.57.30596.711D1F65@pb1.pair.com> References: <91.57.30596.711D1F65@pb1.pair.com> Date: Tue, 22 Mar 2016 19:40:07 -0400 Message-ID: To: Andrea Faulds Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a1136a210bcc7fc052eabbb16 Subject: Re: [PHP-DEV] Re: [RFC] RFC4648 encoding From: scott@paragonie.com (Scott Arciszewski) --001a1136a210bcc7fc052eabbb16 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Mar 22, 2016 at 7:11 PM, Andrea Faulds wrote: > Hi Scott, > > Scott Arciszewski wrote: > >> PHP already offers bin2hex()/hex2bin() and >> base64_encode()/base64_decode(). >> This covers part, but not all, of RFC 4648. >> >> I'd like to extend the coverage to include, at minimum, Base32. >> > > Sounds good. It fills a gap and would doubtless be useful for some > applications. > > This made me wonder if we should add a generalised arbitrary-base with > arbitrary character set pair of encoder and decoder functions. But that's= a > niche use case, they're simple enough to do in userland. > > I'd also like to make these functions to be written to resist cache-timin= g >> attacks (i.e. when used to encode/decode encryption keys for long-term >> storage). Userland PoC: >> https://github.com/paragonie/constant_time_encoding >> >> http://blog.ircmaxell.com/2014/11/its-all-about-time.html >> >> These modifications can either be made in-place (at a negligble cost on >> the >> scale of nanoseconds) or they can be an alternative implementation. i.e. >> >> * bin2hex_ts() >> * base64_encode_ts() >> * base32_encode_ts() >> > > Unless there's a huge, and actually problematic, performance difference, > then I'd suggest we replace our existing implementations, rather than > adding new functions. This way existing code potentially benefits from th= e > security improvement, we don't give developers an unncessary choice, and > there's no extra clutter. > > One more thing, only vaguely on-topic: the base64_decode/_encode function= s > don't let you specify whether you want "base64" or the variant "base64url= ", > they always use the former. You can use a regular expression or strtr() t= o > convert the input/output, of course, but it would be more efficient (and > perhaps for security purposes, less likely to allow timing attacks?) if > there was built-in support. So, should we add a parameter to these > functions to specify if the base64url variant is to be used? > > Thanks for your proposal! > > -- > Andrea Faulds > https://ajf.me/ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > =E2=80=8BHi Andrea, =E2=80=8BThe performance impact should be negligible; ircmaxell found a dif= ference of 5 microseconds. Re: Base64url, that was another question I'd been pondering. My PoC, based on the work of Sc00bz, covers all of RFC 4648. That includes base32hex and base64urlsafe. Do we want to cover those as well? I've noticed a lot of projects using a url-safe variant, so there may be popular demand for it. Scott Arciszewski Chief Development Officer Paragon Initiative Enterprises =E2=80=8B --001a1136a210bcc7fc052eabbb16--