Newsgroups: php.doc,php.internals Path: news.php.net Xref: news.php.net php.doc:969386550 php.internals:98791 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45580 invoked from network); 13 Apr 2017 21:23:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Apr 2017 21:23:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@ohgaki.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@ohgaki.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ohgaki.net designates 180.42.98.130 as permitted sender) X-PHP-List-Original-Sender: yohgaki@ohgaki.net X-Host-Fingerprint: 180.42.98.130 ns1.es-i.jp Received: from [180.42.98.130] ([180.42.98.130:46678] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E3/51-31410-54CEFE85 for ; Thu, 13 Apr 2017 17:23:19 -0400 Received: (qmail 35176 invoked by uid 89); 13 Apr 2017 21:23:13 -0000 Received: from unknown (HELO mail-qk0-f173.google.com) (yohgaki@ohgaki.net@209.85.220.173) by 0 with ESMTPA; 13 Apr 2017 21:23:13 -0000 Received: by mail-qk0-f173.google.com with SMTP id p68so58054305qke.1; Thu, 13 Apr 2017 14:23:13 -0700 (PDT) X-Gm-Message-State: AN3rC/4S3OzPGWQt8DvAuenNe6gS9l+He+zWxby/dbcMz6sEz83Jw+3a qsY1h5tcjNMdIQ3majsdHkxibwWCxw== X-Received: by 10.55.147.131 with SMTP id v125mr4143592qkd.39.1492118586866; Thu, 13 Apr 2017 14:23:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.27.179 with HTTP; Thu, 13 Apr 2017 14:22:26 -0700 (PDT) In-Reply-To: <1924612862.1298112.1492071094545.JavaMail.zimbra@pieterhordijk.com> References: <0285A0ED-A39F-46C9-A927-3C786F2B256D@koalephant.com> <1924612862.1298112.1492071094545.JavaMail.zimbra@pieterhordijk.com> Date: Fri, 14 Apr 2017 06:22:26 +0900 X-Gmail-Original-Message-ID: Message-ID: To: Pieter Hordijk Cc: Joe Watkins , Andrey Andreev , "internals@lists.php.net" , PHP Documentation ML Content-Type: multipart/alternative; boundary=94eb2c08bb92557b77054d12ee36 Subject: Re: [PHP-DEV] [RFC][VOTE] Improve hash_hkdf() parameter From: yohgaki@ohgaki.net (Yasuo Ohgaki) --94eb2c08bb92557b77054d12ee36 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Pieter and all, On Thu, Apr 13, 2017 at 5:11 PM, Pieter Hordijk wrote: > Is this really something we need in our official docs instead of for > example > on a personal blog? > I wrote draft doc patch. Please verify. Index: en/reference/hash/functions/hash-hkdf.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- en/reference/hash/functions/hash-hkdf.xml (=E3=83=AA=E3=83=93=E3=82= =B8=E3=83=A7=E3=83=B3 342317) +++ en/reference/hash/functions/hash-hkdf.xml (=E4=BD=9C=E6=A5=AD=E3=82= =B3=E3=83=94=E3=83=BC) @@ -3,7 +3,7 @@ hash_hkdf - Generate a HKDF key derivation of a supplied key input + Derive secure new key from existing key by using HKDF &reftitle.description; @@ -16,6 +16,20 @@ stringsalt'= ' + + RFC 5869 defines HKDF (HMAC based Key Derivation Function) which + is general purpose KDF. HKDF could be useful for many PHP + applications that require temporary keys, such CSRF token, + pre-signed key for URI, password for password protected + URI, and so on. + + + + When info and length + is not required for your program, more efficient + hash_hmac could be used instead. + + &reftitle.parameters; @@ -25,7 +39,7 @@ algo - Name of selected hashing algorithm (i.e. "sha256", "sha512", "haval160,4", etc..) + Name of selected hashing algorithm (i.e. "sha3-256", "sha3-512", "sha256", "sha512", "haval160,4", etc..) See hash_algos for a list of supported algorithms. @@ -39,7 +53,7 @@ ikm - Input keying material (raw binary). Cannot be empty. + Input keying material. Cannot be empty. @@ -60,7 +74,8 @@ info - Application/context-specific info string. + Application/context-specific info string. Info is intended for + public information such as user ID, protocol version, etc. @@ -71,8 +86,32 @@ Salt to use during derivation. - While optional, adding random salt significantly improves the strength of HKDF. + While optional, adding random salt significantly improves the + strength of HKDF. Salt could be either secret or + non-secret. It is used as "Pre Shared Key" in many use cases. + Strong value is preferred. e.g. Use random_bytes. + Optimal salt size is size of used hash algorithm. + + + Although salt is the last optional parameter, salt is the + most important parameter for key security. Omitted salt is + indication of inappropriate design in most cases. Users must + set appropriate salt value whenever it is possible. Omit salt + only when it cannot be used. + + + Strong salt is mandatory and must be kept secret when input + key is weak, otherwise input key security will not be kept. + Even when input key is strong, providing strong salt is the + best practice for the best possible key security. + + + Salt must not be able to be controlled by users. i.e. User + must not be able to set salt value and get derived key. User + controlled salt allows input key analysis to attackers. + + @@ -101,6 +140,99 @@ &reftitle.examples; + URI specific CSRF token that supports expiration by <function>hash_hkdf</function> + + +]]> + + + Common CSRF token uses the same token value for a session and all + URI. This example CSRF token expires and is specific to a + URI. i.e. CSRF token http://example.com/form_A/ is not valid for + http://example.com/form_B/ Since token value is computed, no + database is required. + + + + + <function>hash_hkdf</function> example + + + <function>hash_hkdf</function> bad example + + Users must not simply extend input key material length. HKDF does + not add additional entropy automatically. Therefore, weak key + remains weak unless strong salt is supplied. Following is bad + example. + + + +]]> + + + @@ -130,6 +286,7 @@ &reftitle.seealso; + hash_hmac hash_pbkdf2 RFC 5869 userland implementation -- Yasuo Ohgaki yohgaki@ohgaki.net --94eb2c08bb92557b77054d12ee36--